使用 Serilog XML 配置指定自定义增强器
Specifying a custom enricher using Serilog XML configuration
有很多使用应用程序设置配置接收器及其属性的示例。但是,我无法真正全神贯注于通过应用程序设置配置自定义增强器。这可以做到吗?我尝试使用 class 的完整路径和程序集的名称来指定配置,但它似乎不起作用。这是我尝试使用的配置示例:
<add key="serilog:enrich:with" value="MyApp.Logging.Serilog.MyEnricher, MyApp" />
键值对语法目前需要为这种情况定义的扩展方法才能工作,例如:
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" />
有很多使用应用程序设置配置接收器及其属性的示例。但是,我无法真正全神贯注于通过应用程序设置配置自定义增强器。这可以做到吗?我尝试使用 class 的完整路径和程序集的名称来指定配置,但它似乎不起作用。这是我尝试使用的配置示例:
<add key="serilog:enrich:with" value="MyApp.Logging.Serilog.MyEnricher, MyApp" />
键值对语法目前需要为这种情况定义的扩展方法才能工作,例如:
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" />