| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | using Microsoft.Extensions.Logging; |
| | 4 | | using System.Net; |
| | 5 | |
|
| | 6 | | namespace IceRpc.Internal; |
| | 7 | |
|
| | 8 | | /// <summary>Provides extension methods for <see cref="ILogger" />. They are used by <see cref="IProtocolConnection" /> |
| | 9 | | /// implementations.</summary> |
| | 10 | | internal static partial class ProtocolLoggerExtensions |
| | 11 | | { |
| | 12 | | [LoggerMessage( |
| | 13 | | EventId = (int)ProtocolEventIds.ConnectionAccepted, |
| | 14 | | EventName = nameof(ProtocolEventIds.ConnectionAccepted), |
| | 15 | | Level = LogLevel.Debug, |
| | 16 | | Message = "Listener '{ServerAddress}' accepted connection from '{RemoteNetworkAddress}'")] |
| | 17 | | internal static partial void LogConnectionAccepted( |
| | 18 | | this ILogger logger, |
| | 19 | | ServerAddress serverAddress, |
| | 20 | | EndPoint remoteNetworkAddress); |
| | 21 | |
|
| | 22 | | [LoggerMessage( |
| | 23 | | EventId = (int)ProtocolEventIds.ConnectionAcceptFailed, |
| | 24 | | EventName = nameof(ProtocolEventIds.ConnectionAcceptFailed), |
| | 25 | | Level = LogLevel.Critical, |
| | 26 | | Message = "Listener '{ServerAddress}' failed to accept a new connection and stopped accepting connections")] |
| | 27 | | internal static partial void LogConnectionAcceptFailed( |
| | 28 | | this ILogger logger, |
| | 29 | | ServerAddress serverAddress, |
| | 30 | | Exception exception); |
| | 31 | |
|
| | 32 | | [LoggerMessage( |
| | 33 | | EventId = (int)ProtocolEventIds.ConnectionAcceptFailedWithRetryableException, |
| | 34 | | EventName = nameof(ProtocolEventIds.ConnectionAcceptFailedWithRetryableException), |
| | 35 | | Level = LogLevel.Debug, |
| | 36 | | Message = "Listener '{ServerAddress}' failed to accept a new connection but continues accepting connections")] |
| | 37 | | internal static partial void LogConnectionAcceptFailedWithRetryableException( |
| | 38 | | this ILogger logger, |
| | 39 | | ServerAddress serverAddress, |
| | 40 | | Exception exception); |
| | 41 | |
|
| | 42 | | [LoggerMessage( |
| | 43 | | EventId = (int)ProtocolEventIds.ConnectionConnected, |
| | 44 | | EventName = nameof(ProtocolEventIds.ConnectionConnected), |
| | 45 | | Level = LogLevel.Debug, |
| | 46 | | Message = "{Kind} connection from '{LocalNetworkAddress}' to '{RemoteNetworkAddress}' connected")] |
| | 47 | | internal static partial void LogConnectionConnected( |
| | 48 | | this ILogger logger, |
| | 49 | | string kind, |
| | 50 | | EndPoint localNetworkAddress, |
| | 51 | | EndPoint remoteNetworkAddress); |
| | 52 | |
|
| | 53 | | internal static void LogConnectionConnected( |
| | 54 | | this ILogger logger, |
| | 55 | | bool isServer, |
| | 56 | | EndPoint localNetworkAddress, |
| | 57 | | EndPoint remoteNetworkAddress) => |
| 24 | 58 | | LogConnectionConnected( |
| 24 | 59 | | logger, |
| 24 | 60 | | isServer ? "Server" : "Client", |
| 24 | 61 | | localNetworkAddress, |
| 24 | 62 | | remoteNetworkAddress); |
| | 63 | |
|
| | 64 | | // Multiple logging methods are using same event id. |
| | 65 | | #pragma warning disable SYSLIB1025 |
| | 66 | | [LoggerMessage( |
| | 67 | | EventId = (int)ProtocolEventIds.ConnectionConnectFailed, |
| | 68 | | EventName = nameof(ProtocolEventIds.ConnectionConnectFailed), |
| | 69 | | Level = LogLevel.Debug, |
| | 70 | | Message = "Client connection failed to connect to '{ServerAddress}'")] |
| | 71 | | internal static partial void LogConnectionConnectFailed( |
| | 72 | | this ILogger logger, |
| | 73 | | ServerAddress serverAddress, |
| | 74 | | Exception exception); |
| | 75 | |
|
| | 76 | | [LoggerMessage( |
| | 77 | | EventId = (int)ProtocolEventIds.ConnectionConnectFailed, |
| | 78 | | EventName = nameof(ProtocolEventIds.ConnectionConnectFailed), |
| | 79 | | Level = LogLevel.Debug, |
| | 80 | | Message = "Server connection failed to connect from '{ServerAddress}' to '{RemoteNetworkAddress}'")] |
| | 81 | | internal static partial void LogConnectionConnectFailed( |
| | 82 | | this ILogger logger, |
| | 83 | | ServerAddress serverAddress, |
| | 84 | | EndPoint remoteNetworkAddress, |
| | 85 | | Exception exception); |
| | 86 | | #pragma warning restore SYSLIB1025 |
| | 87 | |
|
| | 88 | | [LoggerMessage( |
| | 89 | | EventId = (int)ProtocolEventIds.ConnectionDisposed, |
| | 90 | | EventName = nameof(ProtocolEventIds.ConnectionDisposed), |
| | 91 | | Level = LogLevel.Debug, |
| | 92 | | Message = "{Kind} connection from '{LocalNetworkAddress}' to '{RemoteNetworkAddress}' disposed")] |
| | 93 | | internal static partial void LogConnectionDisposed( |
| | 94 | | this ILogger logger, |
| | 95 | | string kind, |
| | 96 | | EndPoint localNetworkAddress, |
| | 97 | | EndPoint remoteNetworkAddress); |
| | 98 | |
|
| | 99 | | internal static void LogConnectionDisposed( |
| | 100 | | this ILogger logger, |
| | 101 | | bool isServer, |
| | 102 | | EndPoint localNetworkAddress, |
| | 103 | | EndPoint remoteNetworkAddress) => |
| 24 | 104 | | LogConnectionDisposed( |
| 24 | 105 | | logger, |
| 24 | 106 | | isServer ? "Server" : "Client", |
| 24 | 107 | | localNetworkAddress, |
| 24 | 108 | | remoteNetworkAddress); |
| | 109 | |
|
| | 110 | | [LoggerMessage( |
| | 111 | | EventId = (int)ProtocolEventIds.ConnectionShutdown, |
| | 112 | | EventName = nameof(ProtocolEventIds.ConnectionShutdown), |
| | 113 | | Level = LogLevel.Debug, |
| | 114 | | Message = "{Kind} connection from '{LocalNetworkAddress}' to '{RemoteNetworkAddress}' shutdown")] |
| | 115 | | internal static partial void LogConnectionShutdown( |
| | 116 | | this ILogger logger, |
| | 117 | | string kind, |
| | 118 | | EndPoint localNetworkAddress, |
| | 119 | | EndPoint remoteNetworkAddress); |
| | 120 | |
|
| | 121 | | internal static void LogConnectionShutdown( |
| | 122 | | this ILogger logger, |
| | 123 | | bool isServer, |
| | 124 | | EndPoint localNetworkAddress, |
| | 125 | | EndPoint remoteNetworkAddress) => |
| 8 | 126 | | LogConnectionShutdown( |
| 8 | 127 | | logger, |
| 8 | 128 | | isServer ? "Server" : "Client", |
| 8 | 129 | | localNetworkAddress, |
| 8 | 130 | | remoteNetworkAddress); |
| | 131 | |
|
| | 132 | | [LoggerMessage( |
| | 133 | | EventId = (int)ProtocolEventIds.ConnectionShutdownFailed, |
| | 134 | | EventName = nameof(ProtocolEventIds.ConnectionShutdownFailed), |
| | 135 | | Level = LogLevel.Debug, |
| | 136 | | Message = "{Kind} connection from '{LocalNetworkAddress}' to '{RemoteNetworkAddress}' failed to shutdown")] |
| | 137 | | internal static partial void LogConnectionShutdownFailed( |
| | 138 | | this ILogger logger, |
| | 139 | | string kind, |
| | 140 | | EndPoint localNetworkAddress, |
| | 141 | | EndPoint remoteNetworkAddress, |
| | 142 | | Exception exception); |
| | 143 | |
|
| | 144 | | internal static void LogConnectionShutdownFailed( |
| | 145 | | this ILogger logger, |
| | 146 | | bool isServer, |
| | 147 | | EndPoint localNetworkAddress, |
| | 148 | | EndPoint remoteNetworkAddress, |
| | 149 | | Exception exception) => |
| 4 | 150 | | LogConnectionShutdownFailed( |
| 4 | 151 | | logger, |
| 4 | 152 | | isServer ? "Server" : "Client", |
| 4 | 153 | | localNetworkAddress, |
| 4 | 154 | | remoteNetworkAddress, |
| 4 | 155 | | exception); |
| | 156 | |
|
| | 157 | | [LoggerMessage( |
| | 158 | | EventId = (int)ProtocolEventIds.DispatchFailed, |
| | 159 | | EventName = nameof(ProtocolEventIds.DispatchFailed), |
| | 160 | | Message = "Dispatch of '{Operation}' on '{Path}' from '{RemoteNetworkAddress}' failed")] |
| | 161 | | internal static partial void LogDispatchFailed( |
| | 162 | | this ILogger logger, |
| | 163 | | LogLevel logLevel, |
| | 164 | | string operation, |
| | 165 | | string path, |
| | 166 | | EndPoint remoteNetworkAddress, |
| | 167 | | Exception exception); |
| | 168 | |
|
| | 169 | | [LoggerMessage( |
| | 170 | | EventId = (int)ProtocolEventIds.DispatchRefused, |
| | 171 | | EventName = nameof(ProtocolEventIds.DispatchRefused), |
| | 172 | | Message = "Refused dispatch from '{RemoteNetworkAddress}'")] |
| | 173 | | internal static partial void LogDispatchRefused( |
| | 174 | | this ILogger logger, |
| | 175 | | LogLevel logLevel, |
| | 176 | | EndPoint remoteNetworkAddress, |
| | 177 | | Exception exception); |
| | 178 | |
|
| | 179 | | [LoggerMessage( |
| | 180 | | EventId = (int)ProtocolEventIds.RequestPayloadContinuationFailed, |
| | 181 | | EventName = nameof(ProtocolEventIds.RequestPayloadContinuationFailed), |
| | 182 | | Message = "Invocation '{Operation}' on '{Path}' failed to send payload continuation to '{RemoteNetworkAddress}'" |
| | 183 | | internal static partial void LogRequestPayloadContinuationFailed( |
| | 184 | | this ILogger logger, |
| | 185 | | LogLevel logLevel, |
| | 186 | | string operation, |
| | 187 | | string path, |
| | 188 | | EndPoint remoteNetworkAddress, |
| | 189 | | Exception exception); |
| | 190 | |
|
| | 191 | | [LoggerMessage( |
| | 192 | | EventId = (int)ProtocolEventIds.StartAcceptingConnections, |
| | 193 | | EventName = nameof(ProtocolEventIds.StartAcceptingConnections), |
| | 194 | | Level = LogLevel.Debug, |
| | 195 | | Message = "Listener '{ServerAddress}' has started accepting connections")] |
| | 196 | | internal static partial void LogStartAcceptingConnections(this ILogger logger, ServerAddress serverAddress); |
| | 197 | |
|
| | 198 | | [LoggerMessage( |
| | 199 | | EventId = (int)ProtocolEventIds.StopAcceptingConnections, |
| | 200 | | EventName = nameof(ProtocolEventIds.StopAcceptingConnections), |
| | 201 | | Level = LogLevel.Debug, |
| | 202 | | Message = "Listener '{ServerAddress}' has stopped accepting connections")] |
| | 203 | | internal static partial void LogStopAcceptingConnections(this ILogger logger, ServerAddress serverAddress); |
| | 204 | | } |