简体   繁体   English

使用Serilog XML配置指定自定义浓缩器

[英]Specifying a custom enricher using Serilog XML configuration

There are a lot of examples of configuring sinks and their properties using app settings configuration. 有许多使用应用程序设置配置配置接收器及其属性的示例。 However, I can't really wrap my head around configuring a custom enricher via app settings. 但是,我无法通过应用程序设置真正地围绕配置自定义浓缩器。 Can this be done? 可以这样做吗? I've tried to specify the configuration using the full path to my class and assembly's name, but it doesn't seem to work. 我试图使用我的类和程序集名称的完整路径来指定配置,但它似乎不起作用。 Here's an example of the configuration I've tried to use: 这是我尝试使用的配置示例:

<add key="serilog:enrich:with" value="MyApp.Logging.Serilog.MyEnricher, MyApp" />

The key-value pair syntax currently needs an extension method defined for this case to work, eg: 键值对语法当前需要为此案例定义的扩展方法才能工作,例如:

static class MyLoggerEnrichmentConfigurationExtensions
{
    public static LoggerConfiguration WithMyEnricher(this LoggerEnrichmentConfiguration enrich)
    {
        return enrich.With(new MyEnricher());
    }
}

It's then referenced and called like so: 然后引用它并像这样调用:

<add key="serilog:using:MyApp" value="MyApp" />
<add key="serilog:enrich:WithMyEnricher" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM