TechNerd TechNerd - 4 months ago 73
C# Question

Serilog RollingFile

I am trying to use WriteTo.RollingFile with Serilog as the following:

var log = new LoggerConfiguration().WriteTo.RollingFile(
log.Information("this is a log test");

My understanding is that the log file will be created and named based on the date, and also it will write to a new file everyday, however I am getting a new log file for each log entry during the same day!
How to configure Serilog to write to a new file every day so ideally I have a single log file per day?

And is there any archiving process to delete files older than 7 days?


Try below:

 var log = new LoggerConfiguration()
          .WriteTo.RollingFile(@"f:\log\log.txt", retainedFileCountLimit:7) 

The log file name will be automatically log-20150819.txt etc. You do not need to specify the date.