[英]Serilog LoggerConfiguration write to different Sink by context
I have web asp.net MVC application using IdentityServer3
. 我有使用
IdentityServer3
web asp.net MVC应用程序。 I want to split logging to different Sink. 我想将日志记录拆分到其他接收器。 I want to write
IdentityServer3
logging to Trace
, EventLog("IdentityServer3")
and SerilogWeb.Classic.Enrichers
to database MSSqlServer
. 我想将
IdentityServer3
Trace
, EventLog("IdentityServer3")
和SerilogWeb.Classic.Enrichers
到数据库MSSqlServer
。
My configuration is: 我的配置是:
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();
To write a subset of events to a sink, use WriteTo.Logger()
and the Filter
directive. 要将事件的子集写入接收器,请使用
WriteTo.Logger()
和Filter
指令。 Each case will be similar; 每种情况都是相似的; here's the Identity Server one:
这是身份服务器之一:
Log.Logger = new LoggerConfiguration()
.WriteTo.Logger(lc => lc
.Filter.ByIncludingOnly(Matching.FromSource("IdentityServer3"))
.WriteTo.Trace()
.WriteTo.EventLog("IdentityServer3"))
// <snip>
You can apply enrichers either at the outermost level, so that they enrich all events, or on one of the nested logger configurations. 您可以在最外层应用扩展程序,以便它们丰富所有事件,也可以在嵌套的记录器配置之一上应用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.