Serilog - multiple log files

前端 未结 5 1278
太阳男子
太阳男子 2020-11-30 01:19

I am using Serilog for logging and cant\' figure out how to separate log events to different files. For example, I want to log errors to error_log-ddmmyyyy.txt and warnings

5条回答
  •  旧巷少年郎
    2020-11-30 01:48

    I think you need:

    .ByIncludingOnly(evt => evt.Level == LogEventLevel.Warning)
    

    Edit:

    In many cases it's now more succinct to use Serilog.Sinks.Map. With it, the example can be written as:

    Log.Logger = new LoggerConfiuration()
        .WriteTo.Map(
            evt => evt.Level,
            (level, wt) => wt.RollingFile("Logs\\" + level + "-{Date}.log"))
        .CreateLogger();
    

提交回复
热议问题