dfacto-lab / serilog-sinks-file

Serilog file sinks duplicated for file rolling
Apache License 2.0
14 stars 10 forks source link

Incorrect date on rolled files #20

Open alexamiryan opened 1 year ago

alexamiryan commented 1 year ago

I have following configuration:

Log.Logger = new LoggerConfiguration()
     .ReadFrom.AppSettings()
     .WriteTo.PersistentFile(
         "C:\\ProgramData\\myapp\\log.txt",
         persistentFileRollingInterval: PersistentFileRollingInterval.Month,
         preserveLogFilename: true,
         retainedFileCountLimit: null,
         shared: true
     )
     .CreateLogger();

It writes most recent log to log.txt, that's OK. However when month changes it moves current log.txt to log{CurrentYear}{CurrentMonth}.txt filename, which is incorrect. Let's say my log.txt was accumulating during February 2023. When March 1 comes, it should rename log.txt to log202302.txt, but currently it renames it to log202303.txt.

Would be really grateful if you can fix this bug.

KrasnovPavel commented 1 year ago

It isn't a bug, you should use useLastWriteAsTimestamp option to achieve behavior you want.