| | | 1 | | // Copyright (c) ZeroC, Inc. |
| | | 2 | | |
| | | 3 | | using IceRpc.Transports; |
| | | 4 | | using Microsoft.Extensions.Logging; |
| | | 5 | | |
| | | 6 | | namespace IceRpc.Internal; |
| | | 7 | | |
| | | 8 | | /// <summary>Implements <see cref="ITaskExceptionObserver" /> using a <see cref="ILogger" />.</summary> |
| | | 9 | | internal class LogTaskExceptionObserver : ITaskExceptionObserver |
| | | 10 | | { |
| | | 11 | | private readonly ILogger _logger; |
| | | 12 | | |
| | | 13 | | public void DispatchFailed( |
| | | 14 | | IncomingRequest request, |
| | | 15 | | TransportConnectionInformation connectionInformation, |
| | | 16 | | Exception exception) => |
| | 2 | 17 | | _logger.LogDispatchFailed( |
| | 2 | 18 | | GetLogLevel(exception), |
| | 2 | 19 | | request.Operation, |
| | 2 | 20 | | request.Path, |
| | 2 | 21 | | connectionInformation.RemoteNetworkAddress, |
| | 2 | 22 | | exception); |
| | | 23 | | |
| | | 24 | | public void DispatchRefused(TransportConnectionInformation connectionInformation, Exception exception) => |
| | 0 | 25 | | _logger.LogDispatchRefused(GetLogLevel(exception), connectionInformation.RemoteNetworkAddress, exception); |
| | | 26 | | |
| | | 27 | | public void RequestPayloadContinuationFailed( |
| | | 28 | | OutgoingRequest request, |
| | | 29 | | TransportConnectionInformation connectionInformation, |
| | | 30 | | Exception exception) => |
| | 0 | 31 | | _logger.LogRequestPayloadContinuationFailed( |
| | 0 | 32 | | GetLogLevel(exception), |
| | 0 | 33 | | request.Operation, |
| | 0 | 34 | | request.ServiceAddress.Path, |
| | 0 | 35 | | connectionInformation.RemoteNetworkAddress, |
| | 0 | 36 | | exception); |
| | | 37 | | |
| | 36 | 38 | | internal LogTaskExceptionObserver(ILogger logger) => _logger = logger; |
| | | 39 | | |
| | | 40 | | private static LogLevel GetLogLevel(Exception exception) => |
| | 2 | 41 | | exception switch |
| | 2 | 42 | | { |
| | 2 | 43 | | // expected during shutdown for example |
| | 2 | 44 | | OperationCanceledException => LogLevel.Trace, |
| | 2 | 45 | | |
| | 2 | 46 | | // usually expected, e.g. peer aborts connection |
| | 0 | 47 | | IceRpcException => LogLevel.Debug, |
| | 2 | 48 | | |
| | 2 | 49 | | // unexpected: from the application code (like a payload read exception) or bug in IceRpc |
| | 0 | 50 | | _ => LogLevel.Warning |
| | 2 | 51 | | }; |
| | | 52 | | } |