Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide exception in IDiagnosticContext #270

Closed
angularsen opened this issue Nov 4, 2021 · 1 comment · Fixed by #271 or serilog/serilog-extensions-hosting#56
Closed

Provide exception in IDiagnosticContext #270

angularsen opened this issue Nov 4, 2021 · 1 comment · Fixed by #271 or serilog/serilog-extensions-hosting#56

Comments

@angularsen
Copy link
Contributor

angularsen commented Nov 4, 2021

Is your feature request related to a problem? Please describe.
We use Hellang.Middleware.ProblemDetails to transform unhandled exceptions to ProblemDetails responses.

This means Serilog's RequestLoggingMiddleware does not observe any unhandled exceptions.

In order to log unhandled exceptions in our APIs, we currently use a separate error logging middleware.
This means we get two log events:

  • One from a custom ErrorLogMiddleware.
  • One from Serilog's request log middleware.

We would like to merge the exception data into Serilog's request log event by passing on the exception details via IDiagnosticContext.

Describe the solution you'd like

  • Add IDiagnosticContext.SetException(Exception e).
  • Add DiagnosticContextCollector.TryComplete(out IEnumerable<LogEventProperty>, out Exception)
  • Enrich log event with exception from IDiagnosticContext, unless an unhandled exception takes precedence.

Pull requests
serilog/serilog-extensions-hosting#56
#271

Describe alternatives you've considered
Separate error logging middleware, but then we get two log events instead of one.

Additional context
Current state:
image

Desired state with exception merged into Serilog's request log event:
image

@nblumhardt
Copy link
Member

Thanks for the PR and write-up 👍

Sounds like a reasonable solution; will need to give this some thought but will loop back to it ASAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants