Missleading unhandled exception error log #54433
Labels
area-middleware
Includes: URL rewrite, redirect, response cache/compression, session, and other general middlesware
design-proposal
This issue represents a design proposal for a different issue, linked in the description
Summary
Since we migrated our services to .NET8 we use the recommended
UseExceptionHandler()
middleware to deal with our exceptions. We have one handler which will handle all exceptions by logging them, creating a ProblemDetails response and return true if we were able to handle this all successful. But after some time we saw in our logs the same exception logged by theMicrosoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware
logger with the messageAn unhandled exception has occurred while executing the request.
again.This surprised us as the exception was handled successfully by our handler which returned true. After some research we think that found the reason for this in the middleware implementation. At line 130 the exception will be logged as unhandled but the handlers are checked way later in line 173.
Motivation and goals
Our idea would be to log a exception as unhandled with level error only after all possible handlers are checked and none of them was able to handle the exception to prevent confusion of a unhandled exception error log for a already handled and logged exception.
The text was updated successfully, but these errors were encountered: