diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index d1f87f0a36..4ed675767c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -1015,7 +1015,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http _applicationException = new AggregateException(_applicationException, ex); } - Log.ApplicationError(ex); + Log.ApplicationError(ConnectionId, ex); } private enum HttpVersionType diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs index b5460ecb4c..1b61c3acc9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs @@ -39,5 +39,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure void NotAllConnectionsClosedGracefully(); void ApplicationError(Exception ex); + + void ApplicationError(string connectionId, Exception ex); } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs index f3f12cbd1f..9562b202b5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -22,6 +22,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel private static readonly Action _connectionWroteFin; private static readonly Action _connectionKeepAlive; private static readonly Action _connectionDisconnect; + private static readonly Action _applicationError; + private static readonly Action _applicationErrorWithId; private static readonly Action _connectionError; private static readonly Action _connectionDisconnectedWrite; private static readonly Action _notAllConnectionsClosedGracefully; @@ -43,7 +45,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel _connectionDisconnect = LoggerMessage.Define(LogLevel.Debug, 10, @"Connection id ""{ConnectionId}"" disconnecting."); // ConnectionWrite: Reserved: 11 // ConnectionWriteCallback: Reserved: 12 - // ApplicationError: Reserved: 13 - LoggerMessage.Define overload not present + _applicationError = LoggerMessage.Define(LogLevel.Error, 13, "An unhandled exception thrown by the application."); + _applicationErrorWithId = LoggerMessage.Define(LogLevel.Error, 13, @"Connection id ""{ConnectionId}"" unhandled exception thrown by the application."); _connectionError = LoggerMessage.Define(LogLevel.Information, 14, @"Connection id ""{ConnectionId}"" communication error"); _connectionDisconnectedWrite = LoggerMessage.Define(LogLevel.Debug, 15, @"Connection id ""{ConnectionId}"" write of ""{count}"" bytes to disconnected client."); _notAllConnectionsClosedGracefully = LoggerMessage.Define(LogLevel.Debug, 16, "Some connections failed to close gracefully during server shutdown."); @@ -120,7 +123,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel public virtual void ApplicationError(Exception ex) { - _logger.LogError(13, ex, "An unhandled exception was thrown by the application."); + _applicationError(_logger, ex); + } + + public virtual void ApplicationError(string connectionId, Exception ex) + { + _applicationErrorWithId(_logger, connectionId, ex); } public virtual void ConnectionError(string connectionId, Exception ex)