Search code examples
c#loggingserilog

How roll Serilog text files similar to log4net?


I wounder how to setup Serilog.Sinks.File to produce this:

log.txt <-- current log
log20200704.txt  <-- rolled over yesterday log
log20200703.txt

instead of:

log20200705.txt <-- current log
log20200704.txt  <-- rolled over yesterday log
log20200703.txt

I am used to such behavior since log4net days.


Solution

  • This is currently not supported by the Serilog.Sinks.File and there are no plans to support it in the short term. You can see a long discussion around this on the link below:

    Fixed filename with rolling archive files #40

    You can see an initial attempt to add this feature as a separate package (though it's still early days and has known limitations) on this repository: https://github.com/dfacto-lab/serilog-sinks-file

    Of course, you can always roll your own version of Serilog.Sinks.File that adds the behavior you're looking for.


    Other, related links: