【问题标题】:Specifying a custom enricher using Serilog XML configuration使用 Serilog XML 配置指定自定义扩充器
【发布时间】:2018-07-01 05:51:12
【问题描述】:
有很多使用应用设置配置来配置接收器及其属性的示例。但是,我无法真正通过应用程序设置来配置自定义浓缩器。这可以做到吗?我尝试使用我的类和程序集名称的完整路径来指定配置,但它似乎不起作用。这是我尝试使用的配置示例:
<add key="serilog:enrich:with" value="MyApp.Logging.Serilog.MyEnricher, MyApp" />
【问题讨论】:
标签:
c#
xml
app-config
serilog
【解决方案1】:
键值对语法目前需要为此案例定义的扩展方法才能工作,例如:
static class MyLoggerEnrichmentConfigurationExtensions
{
public static LoggerConfiguration WithMyEnricher(this LoggerEnrichmentConfiguration enrich)
{
return enrich.With(new MyEnricher());
}
}
然后像这样引用和调用它:
<add key="serilog:using:MyApp" value="MyApp" />
<add key="serilog:enrich:WithMyEnricher" />