Skip to content

Commit

Permalink
Avoid logging bad requests as application errors if the connection was
Browse files Browse the repository at this point in the history
aborted.
  • Loading branch information
adityamandaleeka committed Feb 13, 2025
1 parent 81b2894 commit 9d38e0e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,15 @@ private async Task ProcessRequests<TContext>(IHttpApplication<TContext> applicat
// This has to be caught here so StatusCode is set properly before disposing the HttpContext
// (DisposeContext logs StatusCode).
SetBadRequestState(ex);
ReportApplicationError(ex);

if (!_connectionAborted)
{
// Only report bad requests as error-level logs here if the connection hasn't been aborted. This
// prevents noise in the logs for common types of client errors, and we already have a mechanism
// for logging these at a higher level if needed by increasing the log level for
// "Microsoft.AspNetCore.Server.Kestrel.BadRequests".
ReportApplicationError(ex);
}
}
catch (Exception ex)
{
Expand Down

0 comments on commit 9d38e0e

Please sign in to comment.