diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs index e55ad7284..4ac345e70 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -12,8 +12,35 @@ namespace Microsoft.AspNet.Server.Kestrel /// public class KestrelTrace : IKestrelTrace { + private static Action _connectionStart; + private static Action _connectionStop; + private static Action _connectionPause; + private static Action _connectionResume; + private static Action _connectionReadFin; + private static Action _connectionWriteFin; + private static Action _connectionWroteFin; + private static Action _connectionKeepAlive; + private static Action _connectionDisconnect; + protected readonly ILogger _logger; + static KestrelTrace() + { + _connectionStart = LoggerMessage.Define(LogLevel.Debug, 1, @"Connection id ""{ConnectionId}"" started."); + _connectionStop = LoggerMessage.Define(LogLevel.Debug, 2, @"Connection id ""{ConnectionId}"" stopped."); + // ConnectionRead: Reserved: 3 + _connectionPause = LoggerMessage.Define(LogLevel.Debug, 4, @"Connection id ""{ConnectionId}"" paused."); + _connectionResume = LoggerMessage.Define(LogLevel.Debug, 5, @"Connection id ""{ConnectionId}"" resumed."); + _connectionReadFin = LoggerMessage.Define(LogLevel.Debug, 6, @"Connection id ""{ConnectionId}"" received FIN."); + _connectionWriteFin = LoggerMessage.Define(LogLevel.Debug, 7, @"Connection id ""{ConnectionId}"" sending FIN."); + _connectionWroteFin = LoggerMessage.Define(LogLevel.Debug, 8, @"Connection id ""{ConnectionId}"" sent FIN with status ""{Status}""."); + _connectionKeepAlive = LoggerMessage.Define(LogLevel.Debug, 9, @"Connection id ""{ConnectionId}"" completed keep alive response."); + _connectionDisconnect = LoggerMessage.Define(LogLevel.Error, 10, @"Connection id ""{ConnectionId}"" disconnected."); + // ConnectionWrite: Reserved: 11 + // ConnectionWriteCallback: Reserved: 12 + // ApplicationError: Reserved: 13 - LoggerMessage.Define overload not present + } + public KestrelTrace(ILogger logger) { _logger = logger; @@ -21,12 +48,12 @@ public KestrelTrace(ILogger logger) public virtual void ConnectionStart(long connectionId) { - _logger.LogDebug(1, @"Connection id ""{ConnectionId}"" started.", connectionId); + _connectionStart(_logger, connectionId, null); } public virtual void ConnectionStop(long connectionId) { - _logger.LogDebug(2, @"Connection id ""{ConnectionId}"" stopped.", connectionId); + _connectionStop(_logger, connectionId, null); } public virtual void ConnectionRead(long connectionId, int count) @@ -37,37 +64,37 @@ public virtual void ConnectionRead(long connectionId, int count) public virtual void ConnectionPause(long connectionId) { - _logger.LogDebug(4, @"Connection id ""{ConnectionId}"" paused.", connectionId); + _connectionPause(_logger, connectionId, null); } public virtual void ConnectionResume(long connectionId) { - _logger.LogDebug(5, @"Connection id ""{ConnectionId}"" resumed.", connectionId); + _connectionResume(_logger, connectionId, null); } public virtual void ConnectionReadFin(long connectionId) { - _logger.LogDebug(6, @"Connection id ""{ConnectionId}"" received FIN.", connectionId); + _connectionReadFin(_logger, connectionId, null); } public virtual void ConnectionWriteFin(long connectionId) { - _logger.LogDebug(7, @"Connection id ""{ConnectionId}"" sending FIN.", connectionId); + _connectionWriteFin(_logger, connectionId, null); } public virtual void ConnectionWroteFin(long connectionId, int status) { - _logger.LogDebug(8, @"Connection id ""{ConnectionId}"" sent FIN with status ""{Status}"".", connectionId, status); + _connectionWroteFin(_logger, connectionId, status, null); } public virtual void ConnectionKeepAlive(long connectionId) { - _logger.LogDebug(9, @"Connection id ""{ConnectionId}"" completed keep alive response.", connectionId); + _connectionKeepAlive(_logger, connectionId, null); } public virtual void ConnectionDisconnect(long connectionId) { - _logger.LogDebug(10, @"Connection id ""{ConnectionId}"" disconnected.", connectionId); + _connectionDisconnect(_logger, connectionId, null); } public virtual void ConnectionWrite(long connectionId, int count) diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 983017cfa..c89297337 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -904,12 +904,12 @@ private class TestApplicationErrorLogger : ILogger public IDisposable BeginScopeImpl(object state) { - throw new NotImplementedException(); + return new Disposable(() => { }); } public bool IsEnabled(LogLevel logLevel) { - throw new NotImplementedException(); + return true; } public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter)