【问题标题】:Serilog LoggerConfiguration write to different Sink by contextSerilog LoggerConfiguration 按上下文写入不同的 Sink
【发布时间】:2016-12-06 20:32:20
【问题描述】:

我有使用 IdentityServer3 的 web asp.net MVC 应用程序。 我想将日志记录拆分到不同的接收器。 我想写IdentityServer3日志到TraceEventLog("IdentityServer3")SerilogWeb.Classic.Enrichers到数据库MSSqlServer

我的配置是:

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();

【问题讨论】:

    标签: c# asp.net .net logging serilog


    【解决方案1】:

    要将事件子集写入接收器,请使用 WriteTo.Logger()Filter 指令。每个案例都是相似的;这是身份服务器之一:

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

    您可以在最外层应用丰富器,以便丰富所有事件,也可以在嵌套记录器配置之一上应用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-24
      • 1970-01-01
      • 1970-01-01
      • 2021-09-15
      • 2018-05-16
      相关资源
      最近更新 更多