| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using Microsoft.Extensions.Logging; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF.Channels |
| | | 8 | | { |
| | | 9 | | internal class NetNamedPipeTrace : ILogger |
| | | 10 | | { |
| | | 11 | | private readonly ILogger _generalLogger; |
| | | 12 | | private readonly ILogger _connectionLogger; |
| | | 13 | | |
| | 0 | 14 | | public NetNamedPipeTrace(ILoggerFactory loggerFactory, ILogger connectionLogger) |
| | | 15 | | { |
| | 0 | 16 | | _generalLogger = loggerFactory.CreateLogger("CoreWCF.NetNamedPipe"); |
| | 0 | 17 | | _connectionLogger = connectionLogger; |
| | 0 | 18 | | } |
| | | 19 | | |
| | | 20 | | public void ConnectionStart(string connectionId) |
| | | 21 | | { |
| | 0 | 22 | | ConnectionsLog.ConnectionStart(_connectionLogger, connectionId); |
| | 0 | 23 | | } |
| | | 24 | | |
| | | 25 | | public void ConnectionStop(string connectionId) |
| | | 26 | | { |
| | 0 | 27 | | GeneralLog.ConnectionStop(_generalLogger, connectionId); |
| | 0 | 28 | | } |
| | | 29 | | |
| | | 30 | | public void LogBytes(string method, int count, string data) |
| | | 31 | | { |
| | 0 | 32 | | ConnectionsLog.ConnectionLogging(_connectionLogger, method, count, data); |
| | 0 | 33 | | } |
| | | 34 | | |
| | | 35 | | public void ConnectionAccepted(string connectionId) |
| | | 36 | | { |
| | 0 | 37 | | ConnectionsLog.ConnectionAccepted(_connectionLogger, connectionId); |
| | 0 | 38 | | } |
| | | 39 | | |
| | | 40 | | public void ConnectionError(string connectionId, Exception ex) |
| | | 41 | | { |
| | 0 | 42 | | ConnectionsLog.ConnectionError(_connectionLogger, connectionId, ex); |
| | 0 | 43 | | } |
| | | 44 | | |
| | | 45 | | public void ConnectionReadEnd(string connectionId) |
| | | 46 | | { |
| | 0 | 47 | | ConnectionsLog.ConnectionReadEnd(_connectionLogger, connectionId); |
| | 0 | 48 | | } |
| | | 49 | | |
| | | 50 | | public void ConnectionPause(string connectionId) |
| | | 51 | | { |
| | 0 | 52 | | ConnectionsLog.ConnectionPause(_connectionLogger, connectionId); |
| | 0 | 53 | | } |
| | | 54 | | |
| | | 55 | | public void ConnectionResume(string connectionId) |
| | | 56 | | { |
| | 0 | 57 | | ConnectionsLog.ConnectionResume(_connectionLogger, connectionId); |
| | 0 | 58 | | } |
| | | 59 | | |
| | | 60 | | internal void ConnectionDisconnect(string connectionId, string reason) |
| | | 61 | | { |
| | 0 | 62 | | ConnectionsLog.ConnectionDisconnect(_connectionLogger, connectionId, reason); |
| | 0 | 63 | | } |
| | | 64 | | |
| | | 65 | | internal void LogConnectionError(int eventId, Exception exception, string message) |
| | | 66 | | { |
| | 0 | 67 | | _connectionLogger.LogError(eventId, exception, message); |
| | 0 | 68 | | } |
| | | 69 | | |
| | | 70 | | public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exce |
| | 0 | 71 | | => _generalLogger.Log(logLevel, eventId, state, exception, formatter); |
| | | 72 | | |
| | 0 | 73 | | public bool IsEnabled(LogLevel logLevel) => _generalLogger.IsEnabled(logLevel); |
| | | 74 | | |
| | 0 | 75 | | public IDisposable BeginScope<TState>(TState state) where TState : notnull => _generalLogger.BeginScope(state); |
| | | 76 | | |
| | | 77 | | private static partial class ConnectionsLog |
| | | 78 | | { |
| | | 79 | | // TODO: Replace with LoggerMessageAttribute once moved to .NET 6 |
| | | 80 | | |
| | | 81 | | //[LoggerMessage(1, LogLevel.Debug, @"Connection id ""{ConnectionId}"" started.", EventName = "ConnectionSta |
| | | 82 | | //public static partial void ConnectionStart(ILogger logger, string connectionId); |
| | 0 | 83 | | private static Action<ILogger, string, Exception> s_connectionStart = LoggerMessage.Define<string>( |
| | 0 | 84 | | LogLevel.Debug, |
| | 0 | 85 | | new EventId(1, "ConnectionStart"), |
| | 0 | 86 | | @"Connection id ""{ConnectionId}"" started."); |
| | 0 | 87 | | public static void ConnectionStart(ILogger logger, string connectionId) => s_connectionStart(logger, connect |
| | | 88 | | |
| | | 89 | | //[LoggerMessage(2, LogLevel.Debug, @"Connection id ""{ConnectionId}"" unexpected error.", EventName = "Conn |
| | | 90 | | //private static partial void ConnectionError(ILogger logger, string connectionId, Exception ex); |
| | 0 | 91 | | private static Action<ILogger, string, Exception> s_connectionError = LoggerMessage.Define<string>( |
| | 0 | 92 | | LogLevel.Debug, |
| | 0 | 93 | | new EventId(2, "ConnectionError"), |
| | 0 | 94 | | @"Connection id ""{ConnectionId}"" unexpected error."); |
| | 0 | 95 | | public static void ConnectionError(ILogger logger, string connectionId, Exception ex) => s_connectionError(l |
| | | 96 | | |
| | | 97 | | //[LoggerMessage(4, LogLevel.Debug, @"Connection id ""{ConnectionId}"" paused.", EventName = "ConnectionPaus |
| | | 98 | | //private static partial void ConnectionPause(ILogger logger, string connectionId); |
| | 0 | 99 | | private static Action<ILogger, string, Exception> s_connectionPause = LoggerMessage.Define<string>( |
| | 0 | 100 | | LogLevel.Debug, |
| | 0 | 101 | | new EventId(4, "ConnectionPause"), |
| | 0 | 102 | | @"Connection id ""{ConnectionId}"" paused."); |
| | 0 | 103 | | public static void ConnectionPause(ILogger logger, string connectionId) => s_connectionPause(logger, connect |
| | | 104 | | |
| | | 105 | | //[LoggerMessage(5, LogLevel.Debug, @"Connection id ""{ConnectionId}"" resumed.", EventName = "ConnectionRes |
| | | 106 | | //private static partial void ConnectionResume(ILogger logger, string connectionId); |
| | 0 | 107 | | private static Action<ILogger, string, Exception> s_connectionResume = LoggerMessage.Define<string>( |
| | 0 | 108 | | LogLevel.Debug, |
| | 0 | 109 | | new EventId(5, "ConnectionResume"), |
| | 0 | 110 | | @"Connection id ""{ConnectionId}"" resumed."); |
| | 0 | 111 | | public static void ConnectionResume(ILogger logger, string connectionId) => s_connectionResume(logger, conne |
| | | 112 | | |
| | | 113 | | //[LoggerMessage(6, LogLevel.Debug, @"Connection id ""{ConnectionId}"" received end of stream.", EventName = |
| | | 114 | | //public static partial void ConnectionReadEnd(ILogger logger, string connectionId); |
| | 0 | 115 | | private static Action<ILogger, string, Exception> s_connectionReadEnd = LoggerMessage.Define<string>( |
| | 0 | 116 | | LogLevel.Debug, |
| | 0 | 117 | | new EventId(6, "ConnectionReadEnd"), |
| | 0 | 118 | | @"Connection id ""{ConnectionId}"" received end of stream."); |
| | 0 | 119 | | public static void ConnectionReadEnd(ILogger logger, string connectionId) => s_connectionReadEnd(logger, con |
| | | 120 | | |
| | | 121 | | //[LoggerMessage(7, LogLevel.Debug, @"Connection id ""{ConnectionId}"" disconnecting stream because: ""{Reas |
| | | 122 | | //private static partial void ConnectionDisconnect(ILogger logger, string connectionId, string reason); |
| | 0 | 123 | | private static Action<ILogger, string, string, Exception> s_connectionDisconnect = LoggerMessage.Define<stri |
| | 0 | 124 | | LogLevel.Debug, |
| | 0 | 125 | | new EventId(7, "ConnectionDisconnect"), |
| | 0 | 126 | | @"Connection id ""{ConnectionId}"" disconnecting stream because: ""{Reason}"""); |
| | 0 | 127 | | public static void ConnectionDisconnect(ILogger logger, string connectionId, string reason) => s_connectionD |
| | | 128 | | |
| | | 129 | | //[LoggerMessage(1059, LogLevel.Trace, "{method}[{byteCount}]{data}", EventName = "ConnectionLogging")] |
| | | 130 | | //public static partial void LogBytes(ILogger logger, string method, int count, string data); |
| | 0 | 131 | | private static Action<ILogger, string, int, string, Exception> s_connectionLogging = LoggerMessage.Define<st |
| | 0 | 132 | | LogLevel.Trace, |
| | 0 | 133 | | new EventId(1059, "ConnectionLogging"), |
| | 0 | 134 | | "{method}[{byteCount}]{data}"); |
| | 0 | 135 | | public static void ConnectionLogging(ILogger logger, string method, int count, string data) => s_connectionL |
| | | 136 | | |
| | | 137 | | //[LoggerMessage(4, LogLevel.Debug, @"Connection id ""{ConnectionId}"" paused.", EventName = "ConnectionPaus |
| | | 138 | | //public static partial void ConnectionPause(ILogger logger, string connectionId); |
| | | 139 | | |
| | | 140 | | //[LoggerMessage(5, LogLevel.Debug, @"Connection id ""{ConnectionId}"" resumed.", EventName = "ConnectionRes |
| | | 141 | | //public static partial void ConnectionResume(ILogger logger, string connectionId); |
| | | 142 | | |
| | | 143 | | //[LoggerMessage(9, LogLevel.Debug, @"Connection id ""{ConnectionId}"" completed keep alive response.", Even |
| | | 144 | | //public static partial void ConnectionKeepAlive(ILogger logger, string connectionId); |
| | | 145 | | |
| | | 146 | | //[LoggerMessage(10, LogLevel.Debug, @"Connection id ""{ConnectionId}"" disconnecting.", EventName = "Connec |
| | | 147 | | //public static partial void ConnectionDisconnect(ILogger logger, string connectionId); |
| | | 148 | | |
| | | 149 | | //[LoggerMessage(16, LogLevel.Debug, "Some connections failed to close gracefully during server shutdown.", |
| | | 150 | | //public static partial void NotAllConnectionsClosedGracefully(ILogger logger); |
| | | 151 | | |
| | | 152 | | //[LoggerMessage(21, LogLevel.Debug, "Some connections failed to abort during server shutdown.", EventName = |
| | | 153 | | //public static partial void NotAllConnectionsAborted(ILogger logger); |
| | | 154 | | |
| | | 155 | | //[LoggerMessage(24, LogLevel.Warning, @"Connection id ""{ConnectionId}"" rejected because the maximum numbe |
| | | 156 | | //public static partial void ConnectionRejected(ILogger logger, string connectionId); |
| | | 157 | | |
| | | 158 | | //[LoggerMessage(34, LogLevel.Information, @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier |
| | | 159 | | //public static partial void ApplicationAbortedConnection(ILogger logger, string connectionId, string traceI |
| | | 160 | | |
| | | 161 | | //[LoggerMessage(39, LogLevel.Debug, @"Connection id ""{ConnectionId}"" accepted.", EventName = "ConnectionA |
| | | 162 | | //public static partial void ConnectionAccepted(ILogger logger, string connectionId); |
| | 0 | 163 | | private static Action<ILogger, string, Exception> s_connectionAccepted = LoggerMessage.Define<string>( |
| | 0 | 164 | | LogLevel.Debug, |
| | 0 | 165 | | new EventId(39, "ConnectionAccepted"), |
| | 0 | 166 | | @"Connection id ""{ConnectionId}"" accepted."); |
| | 0 | 167 | | public static void ConnectionAccepted(ILogger logger, string connectionId) => s_connectionAccepted(logger, c |
| | | 168 | | |
| | | 169 | | //// Highest shared ID is 63. New consecutive IDs start at 64 |
| | | 170 | | |
| | | 171 | | |
| | | 172 | | } |
| | | 173 | | |
| | | 174 | | private static partial class GeneralLog |
| | | 175 | | { |
| | | 176 | | //[LoggerMessage(2, LogLevel.Debug, @"Connection id ""{ConnectionId}"" stopped.", EventName = "ConnectionSto |
| | | 177 | | //public static partial void ConnectionStop(ILogger logger, string connectionId); |
| | 0 | 178 | | private static Action<ILogger, string, Exception> s_connectionStop = LoggerMessage.Define<string>( |
| | 0 | 179 | | LogLevel.Debug, |
| | 0 | 180 | | new EventId(2, "ConnectionStop"), |
| | 0 | 181 | | @"Connection id ""{ConnectionId}"" stopped."); |
| | 0 | 182 | | public static void ConnectionStop(ILogger logger, string connectionId) => s_connectionStop(logger, connectio |
| | | 183 | | } |
| | | 184 | | } |
| | | 185 | | } |