Skip to content

For the EnrichDiagnosticContext Func maybe pass either the statusCode or the exception variable. #220

Open
@EraYaN

Description

@EraYaN

Is your feature request related to a problem? Please describe.
My main problem is that I want to log more when there has been an exception. And the response code at this point is still 200 in the httpContext.Response object. So I need a separate custom middleware to achieve the desired result.

Describe the solution you'd like
So pass either the ex variable (just like to _getLevel) or the statusCode so I don't need one more Middleware to just do logging when there has been an exception.

Describe alternatives you've considered
You can add an extra Middleware that add these variables to the DiagnosticContext itself.

Extra context
For example:

            if (httpContext.Response.StatusCode > 499)
            {
               // attach immense amounts of stuff. for later debugging
            }

Does not work with Exceptions, since the StatusCode is still 200 at that point the 500 gets passed as a different parameter in the Middleware completion function.

I'd like to do something like:

            if (ex != null || statusCode > 499)
            {
               // attach immense amounts of stuff. for later debugging
            }

I'm not sure how you could add these two without breaking existing code, even if it would be an easy fix with the new discarded _ arguments for users.

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