I am using serilog with asp net core 3
It is setup and logging exceptions automatically - so i have no error handling to log the errors.
I was attempting to add extra context properties to logged items, and have added middleware to log these.
LogContext.PushProperty("Email", email);
LogContext.PushProperty("Url", url);
These are added if i manually log myself but any logs added automatically when an error occurs does not have these items added.
Any ideas?
NOTE: i have read this... https://blog.datalust.co/smart-logging-middleware-for-asp-net-core/ This is the closest i have found to working around the issue, but this catches the exception and manually logs it, which is a shame if this is the only way it can be done.
LogContext.PushProperty/Enrich.FromLogContextdefinitely work on the assumption of ausingand/or stackiness; the values are (and can only be) captured when a Logging call is made (which requires that to be still in the same context, not having unrolled everything and completed the teardown). I've not delved into the things one can do with asp.net core to stash context such that it can travel from such an inner context out to an exception handler middleware, but for me thats not Serilog dept. - Ruben Bartelink