Different log file for different levels in Serilog

I am using serilog and I need to save different log levels to different files ( for example debug-20200708.log for debug level, info-20200798.log for debug level and …)

I used below code but it does not work correctly.

var baseLogger = new Serilog.LoggerConfiguration()     .WriteTo.Logger(l => l         .Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Fatal))         .WriteTo.File(             path: GetLogPath(LogEventLevel.Fatal),             formatter: formatter)      .WriteTo.Logger(l => l         .Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Error))         .WriteTo.File(             path: GetLogPath(LogEventLevel.Error),             formatter: formatter)      .WriteTo.Logger(l => l         .Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Warning))         .WriteTo.File(             path: GetLogPath(LogEventLevel.Warning),             formatter: formatter)      .WriteTo.Logger(l => l         .Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Information))         .WriteTo.File(             path: GetLogPath(LogEventLevel.Information),             formatter: formatter)      .WriteTo.Logger(l => l         .Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Debug))         .WriteTo.File(             path: GetLogPath(LogEventLevel.Debug),             formatter: formatter)      .WriteTo.Logger(l => l         .Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Verbose))         .WriteTo.File(             path: GetLogPath(LogEventLevel.Verbose),             formatter: formatter)     .Enrich.FromLogContext();  _logger = baseLogger.CreateLogger(); 
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.