Reputation: 1057
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" />
Upvotes: 4
Views: 1866
Reputation: 31832
The key-value pair syntax currently needs an extension method defined for this case to work, e.g.:
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" />
Upvotes: 3