Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 443
Anton Krouglov Avatar asked Mar 03 '23 06:03

Anton Krouglov


1 Answers

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:

  • Allow option to keep root log file as most recent #115
  • Properly rotate log files #667
like image 58
C. Augusto Proiete Avatar answered Mar 16 '23 01:03

C. Augusto Proiete