< Summary

Information
Class: IceRpc.Internal.LogTaskExceptionObserver
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/LogTaskExceptionObserver.cs
Tag: 701_22528036593
Line coverage
64%
Covered lines: 16
Uncovered lines: 9
Coverable lines: 25
Total lines: 64
Line coverage: 64%
Branch coverage
25%
Covered branches: 1
Total branches: 4
Branch coverage: 25%
Method coverage
60%
Covered methods: 3
Total methods: 5
Method coverage: 60%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
DispatchFailed(...)100%11100%
DispatchRefused(...)100%210%
RequestPayloadContinuationFailed(...)100%210%
.ctor(...)100%11100%
GetLogLevel(...)25%4.1481.81%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/LogTaskExceptionObserver.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using IceRpc.Transports;
 4using Microsoft.Extensions.Logging;
 5
 6namespace IceRpc.Internal;
 7
 8/// <summary>Implements <see cref="ITaskExceptionObserver" /> using a <see cref="ILogger" />.</summary>
 9internal class LogTaskExceptionObserver : ITaskExceptionObserver
 10{
 11    private readonly ILogger _logger;
 12
 13    [System.Diagnostics.CodeAnalysis.SuppressMessage(
 14        "Performance",
 15        "CA1873:Avoid potentially expensive logging",
 16        Justification = "GetLogLevel is a trivial switch on the exception type and is required to categorize the log.")]
 17    public void DispatchFailed(
 18        IncomingRequest request,
 19        TransportConnectionInformation connectionInformation,
 20        Exception exception) =>
 121        _logger.LogDispatchFailed(
 122            GetLogLevel(exception),
 123            request.Operation,
 124            request.Path,
 125            connectionInformation.RemoteNetworkAddress,
 126            exception);
 27
 28    [System.Diagnostics.CodeAnalysis.SuppressMessage(
 29        "Performance",
 30        "CA1873:Avoid potentially expensive logging",
 31        Justification = "GetLogLevel is a trivial switch on the exception type and is required to categorize the log.")]
 32    public void DispatchRefused(TransportConnectionInformation connectionInformation, Exception exception) =>
 033        _logger.LogDispatchRefused(GetLogLevel(exception), connectionInformation.RemoteNetworkAddress, exception);
 34
 35    [System.Diagnostics.CodeAnalysis.SuppressMessage(
 36        "Performance",
 37        "CA1873:Avoid potentially expensive logging",
 38        Justification = "GetLogLevel is a trivial switch on the exception type and is required to categorize the log.")]
 39    public void RequestPayloadContinuationFailed(
 40        OutgoingRequest request,
 41        TransportConnectionInformation connectionInformation,
 42        Exception exception) =>
 043        _logger.LogRequestPayloadContinuationFailed(
 044            GetLogLevel(exception),
 045            request.Operation,
 046            request.ServiceAddress.Path,
 047            connectionInformation.RemoteNetworkAddress,
 048            exception);
 49
 1850    internal LogTaskExceptionObserver(ILogger logger) => _logger = logger;
 51
 52    private static LogLevel GetLogLevel(Exception exception) =>
 153        exception switch
 154        {
 155            // expected during shutdown for example
 156            OperationCanceledException => LogLevel.Trace,
 157
 158            // usually expected, e.g. peer aborts connection
 059            IceRpcException => LogLevel.Debug,
 160
 161            // unexpected: from the application code (like a payload read exception) or bug in IceRpc
 062            _ => LogLevel.Warning
 163        };
 64}