2016-08-25 97 views

回答

0

如果子記錄器的數量是固定在編譯的時候,你可以使用配置前綴來做到這一點:

Log.Logger = new LoggerConfiguration() 
    .ReadFrom.AppSettings() // default file 
    .WriteTo.Logger(lc => lc 
     .ReadFrom.AppSettings(filePath: "other1.config"))    
    .WriteTo.Logger(lc => lc 
     .ReadFrom.AppSettings(filePath: "other2.config")) 
    .CreateLogger(); 

有在Serilog.Settings.AppSettings不支持,但在理論上沒有什麼預防如果某人能夠實施它,它會被添加。

0

試試這個

Startup.cs/Global.asax.cs中

Log.Logger = new LoggerConfiguration() 
      .WriteTo 
      .Logger(x => x.Filter 
      .ByIncludingOnly(logEvent => logEvent.Level == Serilog.Events.LogEventLevel.Error) 
      .ReadFrom 
      .AppSettings("error")) 

      .WriteTo 
      .Logger(x => x.Filter 
      .ByIncludingOnly(logEvent => logEvent.Level == Serilog.Events.LogEventLevel.Information) 
      .ReadFrom 
      .AppSettings("info")).CreateLogger() 

的Web.Config

<add key ="error:serilog:using:RollingFile" value="Serilog.Sinks.RollingFile"/> 
<add key ="error:serilog:write-to:RollingFile.pathFormat" value="C:\log\error {Date}.txt"/> 
<add key ="error:serilog:write-to:RollingFile.formatter" value="Serilog.Formatting.Json.JsonFormatter"/> 

<add key ="info:serilog:using:RollingFile" value="Serilog.Sinks.RollingFile"/> 
<add key ="info:serilog:write-to:RollingFile.pathFormat" value="C:\log\info {Date}.txt"/> 
<add key ="info:serilog:write-to:RollingFile.formatter" value="Serilog.Formatting.Json.JsonFormatter"/> 
+0

請不要添加[相同的答案](http://stackoverflow.com/a/41989190/4687348)畝一些問題。回答最好的一個,並將其餘標記爲重複。請參閱[是否可以爲幾個問題添加重複答案?](http://meta.stackexchange.com/q/104227/347985) – FelixSFD

相關問題