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 8 forks source link

How to use? #11

Closed josephwambura closed 2 years ago

josephwambura commented 2 years ago

I am trying to add this feature to my project, but it does not work.

<add key="serilog:write-to:File.hooks" value="Serilog.Sinks.File.Archive::ArchiveHooks, Archive" />

running on .Net 4.8 and using the xml config files.

cocowalla commented 2 years ago

You need to configure your sink to use the hook. To do this, you will first need to create a public static class that can provide the configuration system with a configured instance of ArchiveHooks:

using Serilog.Sinks.File.Archive;

namespace MyApp.Logging;

public class SerilogHooks
{
    public static ArchiveHooks MyArchiveHooks => new ArchiveHooks(CompressionLevel.Fastest, "C:\\My\\Archive\\Path");
}

You then specify that in your configuration, e.g.

<add key="serilog:write-to:File.hooks" value="MyApp.Logging.SerilogHooks::MyArchiveHooks, MyAssembly" />

I haven't actually verified the above XML config, but it should work.

In the example you posted, it looks like you are pointing towards the wrong config, unless your static class really is Serilog.Sinks.File.Archive.ArchiveHooks in assembly Archive?