我正在使用Serilog,需要将不同的日志级别保存到不同的文件中(例如debug-20200708.log为调试级别,info-20200798.log为信息级别等…)
我使用了以下代码,但它并没有正常工作。
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();