serilog-sinks-file-archive icon indicating copy to clipboard operation
serilog-sinks-file-archive copied to clipboard

zip support

Open MichaRotstein opened this issue 4 years ago • 3 comments

Can we have support for zip files ?

MichaRotstein avatar Jan 27 '21 22:01 MichaRotstein

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.

cocowalla avatar Jan 28 '21 12:01 cocowalla

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?

opheoHeidrich avatar Apr 11 '24 07:04 opheoHeidrich

@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?

cocowalla avatar Apr 11 '24 19:04 cocowalla