2016-12-06 37 views
2

我有使用IdentityServer3的web asp.net MVC應用程序。 我想分割日誌到不同的接收器。 我想寫IdentityServer3登錄到Trace,EventLog("IdentityServer3")SerilogWeb.Classic.Enrichers到數據庫MSSqlServerSerilog LoggerConfiguration通過上下文寫入不同的接收器

我的配置是:

Log.Logger = new LoggerConfiguration() 
       .WriteTo.Trace() 
       .WriteTo.EventLog("IdentityServer3") 
       .Enrich.FromLogContext() 
       //all after this i want to write in database 
       .WriteTo.MSSqlServer("connectionString", "Log") 
       .Enrich.With(new HttpRequestIdEnricher()) 
       .Enrich.With(new HttpRequestRawUrlEnricher()) 
       .Enrich.With(new HttpRequestUserAgentEnricher()) 
       .Enrich.With(new UserNameEnricher()) 
       .CreateLogger(); 

回答

3

要寫出事件的一個子集水槽,使用WriteTo.Logger()Filter指令。每個案例都是相似的;這裏的Identity Server的一個:

Log.Logger = new LoggerConfiguration() 
    .WriteTo.Logger(lc => lc 
     .Filter.ByIncludingOnly(Matching.FromSource("IdentityServer3")) 
     .WriteTo.Trace() 
     .WriteTo.EventLog("IdentityServer3")) 
    // <snip> 

您可以在最外層採用濃縮商要麼,讓他們充實的所有事件,或者在嵌套記錄器配置之一。

相關問題