Serilog - Preserve current log file name and custom archive names

Viewed 45

Currently using:

  • Serilog 2.11.0
  • Serilog.Sinks.File 5.0.0
  • Serilog.Sinks.RollingFile 3.3.0

With the following logger configuration:

        _logger = new LoggerConfiguration()
            .MinimumLevel.Verbose()
            .WriteTo.File(
                HttpContext.Current.Server.MapPath("~/MyApp/App_Data/logs/app.log"),
                rollOnFileSizeLimit: true,
                fileSizeLimitBytes: 10000000,
                shared: true)
            .CreateLogger();

I am trying to figure out if it is possible to maintain the current log file name to name specified in logger configuration and have custom named archived file names. For example:

  • app.log (always current log file)
  • app_20220913.log (archived log file that rolled on size on 2022/09/13)
  • app_20220912.log (archived log file that rolled on size on 2022/09/12)
  • app_20220911.log (archived log file that rolled on size on 2022/09/11)

Compared to current behavior:

  • import_001.log (current log file)
  • import.log (archived log file that rolled on size)

Thanks in advance!

0 Answers
Related