Closed MNF closed 1 year ago
I suppose you use https://github.com/serilog/serilog-settings-configuration.
It looks like the configuration should be:
"Serilog": {
"MinimumLevel": "Debug",
"Enrich": [
"FromLogContext",
{
"Name": "With",
"Args": { "enricher": "Serilog.ThrowContext.ThrowContextEnricher, Serilog.ThrowContext" }
}
],
"WriteTo": [
{
"Name": "Console",
"Args": {
"formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact"
}
}
]
}
(I added FromLogContext and RenderedCompactJsonFormatter because without them we cannot observe context properties).
Unfortunately, this configuration throws System.MemberAccessException: 'Type initializer was not callable.'
. I think this happens because ThrowContextEnricher has a static constructor and serilog-settings-configuration
somehow invokes it instead of instance ctor.
@Tolyandre I'm assuming this is now resolved? The related problem has since been fixed.
Hey @julealgon, thanks for reaching out to me.
I have just tested and it works. I also added a sample csproj https://github.com/Tolyandre/serilog-throw-context-enricher/tree/master/Samples/FileConfigurationSample
So yes, I will close this
It will be good to add to readme an example of configuration as an alternative to hardcoded new LoggerConfiguration() .Enrich.With()-
something like
{ "Serilog": { "MinimumLevel": "Debug", "Using": [ "Serilog.ThrowContext" ], "Enrich": [ "ThrowContextEnricher"], "WriteTo": [ { "Name": "Console" } ] } }
I haven’t tried it yet. Will it work ?