In my WPF .netCore 5 app, I'm using three libraries where each library accepts Microsoft.Extensions.Logging.ILogger at initialization. I'm using Serilog and ILoggerFactory. I create three LoggerConfigurations with different WriteTo.File paths.
//licence manager logger
var serilogLM = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.File(
$"{LogPathSettings.LicenseManagerLogPath}/LicenseManager {LogPathSettings.ShortDateTime}.log",
outputTemplate: "{Timestamp:dd-MM-yyyy HH:mm:ss.fff} [{Level:u3}] {Message:lj}{NewLine}{Exception}")
.CreateLogger();
var licenseManagerLogger = Microsoft.Extensions.Logging.LoggerFactory.Create(l =>
{
l.AddSerilog(serilogLM);
}).CreateLogger("LicenseManager");
//client logger
var serilogClient = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.File($"{LogPathSettings.ClientLogPath}/Client {LogPathSettings.ShortDateTime}.log", outputTemplate: "{Timestamp:dd-MM-yyyy HH:mm:ss.fff} [{Level:u3}] {Message:lj}{NewLine}{Exception}")
.CreateLogger();
var clientLogger = Microsoft.Extensions.Logging.LoggerFactory.Create(l=>
{
l.AddSerilog(serilogClient);
}).CreateLogger("RedClient");
The issue I'm having is that latest LoggerConfiguration overwrites all previous ones, so instead of each library using their own logger, all three log files are created, but all libraries write to logger which was created last. I know there is a catch somewhere, but I couldn't find the solution yet.
So my question is how can I create three Microsoft.Extensions.Logging.ILogger instances each using its own Serilog with custom LoggerConfiguration.
So since serilogClient logger is created last, the licenseManagerLogger uses the same WriteTo.File sink path.
All samples that I found are using simple logging or logging to multiple files based on LogLevel which is not the case here.