2016-05-16 96 views
1

我正在嘗試使用應用程序設置程序包對serilog進行接線,當我運行我的程序時,Serlog抱怨它無法找到RollingFile組件。我沒有使用單個接收器的問題,但多個它給我適合:Serilog - 在應用程序設置中配置多個接收器

<!-- Serilog Configuration --> 
<add key="serilog:using:Email" value="Serilog.Sinks.Email" /> 
<add key="serilog:using:RollingFile" value="Serilog.Sinks.RollingFile" /> 

<!-- Configure Serilog Email Sink --> 
<add key="serilog:write-to:Email"/> 
<add key="serilog:write-to:Email.mailServer" value="***" /> 
<add key="serilog:write-to:Email.toEmail" value="***" /> 
<add key="serilog:write-to:Email.fromEmail" value="***" /> 
<add key="serilog:write-to:Email.mailSubject" value="Notification" /> 
<add key="serilog:write-to:Email.restrictedToMinimumLevel" value="Debug" /> 

<!-- Configure Serilog RollingFile Sink --> 
<add key="serilog:write-to:RollingFile" /> 
<add key="serilog:write-to:RollingFile.restrictedToMinimumLevel" value="Debug" /> 
<add key="serilog:write-to:RollingFile.pathFormat" value="C:\Logs\comply360-user-mgmt-{Date}.txt" /> 
<add key="serilog:write-to:RollingFile.outputTemplate" value="{Timestamp:HH:mm:ss} [{Level}] [{SourceContext}] [{CorrelationId}] {Message}{NewLine}{Exception}" /> 

回答

1

想通了。我不得不使用語句刪除滾動文件。

2

你必須使用前綴在web.config中和在配置這樣

的Web.Config

<!-- Serilog Configuration --> 
<add key="email:serilog:using:Email" value="Serilog.Sinks.Email" /> 
<add key="file:serilog:using:RollingFile" value="Serilog.Sinks.RollingFile"  /> 

<!-- Configure Serilog Email Sink --> 
<add key="email:serilog:write-to:Email"/> 
<add key="email:serilog:write-to:Email.mailServer" value="***" /> 
<add key="email:serilog:write-to:Email.toEmail" value="***" /> 
<add key="email:serilog:write-to:Email.fromEmail" value="***" /> 
<add key="email:serilog:write-to:Email.mailSubject" value="Notification" /> 
<add key="email:serilog:write-to:Email.restrictedToMinimumLevel" value="Debug" /> 

<!-- Configure Serilog RollingFile Sink --> 
<add key="file:serilog:write-to:RollingFile" /> 
<add key="file:serilog:write-to:RollingFile.restrictedToMinimumLevel" value="Debug" /> 
<add key="file:serilog:write-to:RollingFile.pathFormat" value="C:\Logs\comply360-user-mgmt-{Date}.txt" /> 
<add key="file:serilog:write-to:RollingFile.outputTemplate" value="{Timestamp:HH:mm:ss} [{Level}] [{SourceContext}] [{CorrelationId}] {Message}{NewLine}{Exception}" /> 

Startup.cs

Log.Logger = new LoggerConfiguration() 
      .ReadFrom 
      .AppSettings("email") 
      .ReadFrom 
      .AppSettings("file") 
      .CreateLogger() 
相關問題