Thanks @mistyn8!
I did spend about 4 hours trying to get something to work for unhandled exception.
About your examples:
.Enrich.FromGlobalLogContext()
Not an option as it would require me to reconfigure the logger that Umbraco uses, which feels “overkill” just to be able to add an enricher.
If I were to replace the logging initialization, it would be easy to just add my enrichers like so
.Enrich.With<MyCustomEnricher>()
using (_logger.BeginScope(scopeProps))
{
_logger.LogInformation("Account register: {Email} registering for a new account", model.ContactDetails.Email);
}
Since I do not control the code that performs the logging (it’s part of Serilog) I cannot create a new scope when unhandled exceptions are logged.
LovellEnricher : ILogEventEnricher
Yes, this is what I’m doing. The problem was never to implement the enricher but to get it to fire for unhandled exceptions.
If you have a working sample on how to add a custom enricher that runs on unhandled exceptions without replacing the default i logger declaration, it would be cool to see ![]()
I’ve got a workaround that works, so I’m quite happy. But it would be nice if there were a hook to register enrichers during the setup.