0

I am trying to set a minimum level while creating a logger, as reported below:

new LoggerConfiguration()
.MinimumLevel.Error()
.Enrich.FromLogContext()
.WriteTo.Async(a =\> a.File(this.logFile, rollingInterval: RollingInterval.Day, retainedFileCountLimit: this.retention, shared: true, outputTemplate: MY_TEMPLATE))
.CreateLogger();

With this code, the retention is not applied, and all the previous files are not deleted, as the retainedFileCountLimit would be not set. If I set the minimum level to debug with .MinimumLevel.Debug(), files are deleted as foreseen by value of retainedFileCount.

I tried removing the shared mode and I used WriteTo.File(...) instead of WriteTo.Async(...):

new LoggerConfiguration()
.MinimumLevel.Debug()
.Enrich.FromLogContext()
.WriteTo.File(this.logFile, rollingInterval: RollingInterval.Day, retainedFileCountLimit: this.retention, outputTemplate: MY_TEMPLATE)
.CreateLogger();

But the problem persists also with this code.

How could I fix this problem? Thanks.

YellowBlue
  • 651
  • 1
  • 5
  • 5
  • The Async wrapping should definitely make no difference. Are you doing at least one log statement that's triggering a write in each instance to trigger trimming? i.e. if the log statements are being filtered out, it may not get to the sink, and hence trimming may not take place. – Ruben Bartelink May 11 '23 at 08:28
  • (migrated from https://github.com/serilog/serilog-sinks-file/issues/283, where I asked the same questions - thanks for taking the time to move it) – Ruben Bartelink May 11 '23 at 14:31

0 Answers0