Reduce log noise for WebSocket authentication failures - downgrade to Debug level

This commit is contained in:
2026-04-29 08:30:54 -04:00
parent 786c61ba09
commit bad167656a
+16 -5
View File
@@ -83,11 +83,22 @@ public class ExceptionMiddleware
{ {
if (isAuthenticationError) if (isAuthenticationError)
{ {
// Log authentication errors as warnings with user-friendly message // WebSocket authentication failures are expected when clients connect without tokens
_logger.LogWarning( // Log at Debug level to reduce noise, unless it's not a WebSocket endpoint
"Access denied: Unable to process request. Authentication token missing or invalid. URL {Method} {Url}.", if (context.Request.Path.StartsWithSegments("/socket", StringComparison.OrdinalIgnoreCase))
context.Request.Method, {
context.Request.Path); _logger.LogDebug(
"WebSocket connection rejected: Authentication token missing or invalid. IP: {IP}",
context.Connection.RemoteIpAddress);
}
else
{
// Log authentication errors for non-WebSocket endpoints as warnings
_logger.LogWarning(
"Access denied: Unable to process request. Authentication token missing or invalid. URL {Method} {Url}.",
context.Request.Method,
context.Request.Path);
}
} }
else else
{ {