1

Logger.cs:

using System.Configuration;
using System.Threading;
using System;
using Serilog;
using Serilog.Enrichers;
using Serilog.Events;
using Serilog.Sinks.RollingFile;

namespace my.package.Logger
{
    public static class Logger
    {
        static Logger() {
            Log.Logger = new LoggerConfiguration().Enrich.WithThreadId().ReadFrom.AppSettings().CreateLogger();
        }
    }
}

App.config:

  <appSettings>
    <add key="serilog:write-to:RollingFile.pathFormat" value="path\to\LOG{Date}.txt" />
    <add key="serilog:write-to:RollingFile.retainedFileCountLimit" value="2" />
    <add key="serilog:write-to:RollingFile.fileSizeLimitBytes" value="" />
    <add key="serilog:write-to:RollingFile.outputTemplate" value="{Timestamp:yyyy-MM-dd HH:mm.ss,fff} {Level} [{ThreadId}]: {Message}{NewLine}{Exception}" />
    <add key="serilog:minimum-level" value="Debug" />
  </appSettings>

But despite retainedFileCountLimit set to 2, log files accumulate (there are 6 today).

Interesting thing is that if I restart the system (not the service, the whole system), files are correctly cleaned up and only the 2 last files are kept.

Any idea?

Edit1: adding a screenshot of the files: enter image description here

Sebas
  • 21,192
  • 9
  • 55
  • 109

0 Answers0