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.