cocowalla / serilog-sinks-file-archive

Plugin for the Serilog File sink that works with rolling log files, archiving completed log files before they are deleted by Serilog's retention mechanism
Apache License 2.0
31 stars 7 forks source link

zip support #5

Open MichaRotstein opened 3 years ago

MichaRotstein commented 3 years ago

Can we have support for zip files ?

cocowalla commented 3 years ago

I don't see why not, it's simple enough to create ZIP files:

using (ZipArchive archive = ZipFile.Open(targetPath, ZipArchiveMode.Create))
{
    archive.CreateEntryFromFile(path, Path.GetFileName(path), this.compressionLevel);
}

I need to put some thought into how best to expose this new option for the user, and how to organise ArchiveHooks in include it.

opheoHeidrich commented 6 months ago

Can we expect this feature in the foreseeable future? If not, will I get a review if I try to build this feature myself and create a pull request?

cocowalla commented 6 months ago

@opheoHeidrich I don't have much time these days, so it's not coming from me any time soon 😞 - would be happy to accept a contribution from yourself tho!

A simple way to expose this option is just to add a couple of new ArchiveHooks ctors that include a new enum parameter (of type CompressionType or whatever). Then have the original 2 ctors just direct to the new ones, setting the new argument to CompressionType.Gzip.

The new ctors would be Something like:

public ArchiveHooks(CompressionType = CompressionType.Gzip, CompressionLevel compressionLevel = CompressionLevel.Fastest, string targetDirectory = null)
{
  // TODO: implement
}

public ArchiveHooks(int retainedFileCountLimit, CompressionLevel compressionLevel = CompressionLevel.Fastest, string targetDirectory = null)
{
  // TODO: implement
}

Obviously the On* event handlers need to be updated too. Unsure off the top of my head about CompressionLevel with ZipArchive; it might need to be mapped to some other values. So, a simple approach - what do you think?