< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.NetNamedPipeTrace
Assembly: CoreWCF.NetNamedPipe
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetNamedPipe/src/CoreWCF/Channels/NetNamedPipeTrace.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 72
Coverable lines: 72
Total lines: 185
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetNamedPipe/src/CoreWCF/Channels/NetNamedPipeTrace.cs

#LineLine coverage
 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
 4using System;
 5using Microsoft.Extensions.Logging;
 6
 7namespace CoreWCF.Channels
 8{
 9    internal class NetNamedPipeTrace : ILogger
 10    {
 11        private readonly ILogger _generalLogger;
 12        private readonly ILogger _connectionLogger;
 13
 014        public NetNamedPipeTrace(ILoggerFactory loggerFactory, ILogger connectionLogger)
 15        {
 016            _generalLogger = loggerFactory.CreateLogger("CoreWCF.NetNamedPipe");
 017            _connectionLogger = connectionLogger;
 018        }
 19
 20        public void ConnectionStart(string connectionId)
 21        {
 022            ConnectionsLog.ConnectionStart(_connectionLogger, connectionId);
 023        }
 24
 25        public void ConnectionStop(string connectionId)
 26        {
 027            GeneralLog.ConnectionStop(_generalLogger, connectionId);
 028        }
 29
 30        public void LogBytes(string method, int count, string data)
 31        {
 032            ConnectionsLog.ConnectionLogging(_connectionLogger, method, count, data);
 033        }
 34
 35        public void ConnectionAccepted(string connectionId)
 36        {
 037            ConnectionsLog.ConnectionAccepted(_connectionLogger, connectionId);
 038        }
 39
 40        public void ConnectionError(string connectionId, Exception ex)
 41        {
 042            ConnectionsLog.ConnectionError(_connectionLogger, connectionId, ex);
 043        }
 44
 45        public void ConnectionReadEnd(string connectionId)
 46        {
 047            ConnectionsLog.ConnectionReadEnd(_connectionLogger, connectionId);
 048        }
 49
 50        public void ConnectionPause(string connectionId)
 51        {
 052            ConnectionsLog.ConnectionPause(_connectionLogger, connectionId);
 053        }
 54
 55        public void ConnectionResume(string connectionId)
 56        {
 057            ConnectionsLog.ConnectionResume(_connectionLogger, connectionId);
 058        }
 59
 60        internal void ConnectionDisconnect(string connectionId, string reason)
 61        {
 062            ConnectionsLog.ConnectionDisconnect(_connectionLogger, connectionId, reason);
 063        }
 64
 65        internal void LogConnectionError(int eventId, Exception exception, string message)
 66        {
 067            _connectionLogger.LogError(eventId, exception, message);
 068        }
 69
 70        public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exce
 071            => _generalLogger.Log(logLevel, eventId, state, exception, formatter);
 72
 073        public bool IsEnabled(LogLevel logLevel) => _generalLogger.IsEnabled(logLevel);
 74
 075        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);
 083            private static Action<ILogger, string, Exception> s_connectionStart = LoggerMessage.Define<string>(
 084                LogLevel.Debug,
 085                new EventId(1, "ConnectionStart"),
 086                @"Connection id ""{ConnectionId}"" started.");
 087            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);
 091            private static Action<ILogger, string, Exception> s_connectionError = LoggerMessage.Define<string>(
 092                LogLevel.Debug,
 093                new EventId(2, "ConnectionError"),
 094                @"Connection id ""{ConnectionId}"" unexpected error.");
 095            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);
 099            private static Action<ILogger, string, Exception> s_connectionPause = LoggerMessage.Define<string>(
 0100                LogLevel.Debug,
 0101                new EventId(4, "ConnectionPause"),
 0102                @"Connection id ""{ConnectionId}"" paused.");
 0103            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);
 0107            private static Action<ILogger, string, Exception> s_connectionResume = LoggerMessage.Define<string>(
 0108                LogLevel.Debug,
 0109                new EventId(5, "ConnectionResume"),
 0110                @"Connection id ""{ConnectionId}"" resumed.");
 0111            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);
 0115            private static Action<ILogger, string, Exception> s_connectionReadEnd = LoggerMessage.Define<string>(
 0116                LogLevel.Debug,
 0117                new EventId(6, "ConnectionReadEnd"),
 0118                @"Connection id ""{ConnectionId}"" received end of stream.");
 0119            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);
 0123            private static Action<ILogger, string, string, Exception> s_connectionDisconnect = LoggerMessage.Define<stri
 0124                LogLevel.Debug,
 0125                new EventId(7, "ConnectionDisconnect"),
 0126                @"Connection id ""{ConnectionId}"" disconnecting stream because: ""{Reason}""");
 0127            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);
 0131            private static Action<ILogger, string, int, string, Exception> s_connectionLogging = LoggerMessage.Define<st
 0132                LogLevel.Trace,
 0133                new EventId(1059, "ConnectionLogging"),
 0134                "{method}[{byteCount}]{data}");
 0135            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);
 0163            private static Action<ILogger, string, Exception> s_connectionAccepted = LoggerMessage.Define<string>(
 0164                LogLevel.Debug,
 0165                new EventId(39, "ConnectionAccepted"),
 0166                @"Connection id ""{ConnectionId}"" accepted.");
 0167            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);
 0178            private static Action<ILogger, string, Exception> s_connectionStop = LoggerMessage.Define<string>(
 0179                LogLevel.Debug,
 0180                new EventId(2, "ConnectionStop"),
 0181                @"Connection id ""{ConnectionId}"" stopped.");
 0182            public static void ConnectionStop(ILogger logger, string connectionId) => s_connectionStop(logger, connectio
 183        }
 184    }
 185}