Skip to content

Provide exception in IDiagnosticContext #270

Closed
serilog/serilog-extensions-hosting
#56
@angularsen

Description

@angularsen

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions