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

Don't log exception in exception handling middleware #42950

Closed
1 task done
stevendarby opened this issue Jul 27, 2022 · 1 comment
Closed
1 task done

Don't log exception in exception handling middleware #42950

stevendarby opened this issue Jul 27, 2022 · 1 comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Comments

@stevendarby
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

If using UseExceptionHandler() middleware and ExceptionHandlerOptions.ExceptionHandler to handle an exception, the exception is still logged as an Error with the message "An unhandled exception has occurred while executing the request."

This seems wrong - given the name of the middleware & the name of the delegate on the options, this is all about handling an exception, so seeing a log about an unhandled exception is surprising.

This comes up from time to time and workarounds are given for how to remove it from logs e.g. https://stackoverflow.com/questions/59553325/prevent-microsoft-logging-from-log-when-unhandled-exception-thrown

Describe the solution you'd like

Don't log, so people don't have to workaround it. Application code can log it if needed. Perhaps the middleware could log it as an unhandled error, but only after it's given a chance to be handled.

Additional context

No response

@adityamandaleeka
Copy link
Member

Triage: We believe that having the log message here is the appropriate default. As you've already seen, you can disable this by setting your log level to None for Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware

See https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-7.0#configure-logging

@ghost ghost locked as resolved and limited conversation to collaborators Aug 28, 2022
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

No branches or pull requests

4 participants