// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Sockets.Internal { internal static class SocketLoggerExtensions { // Category: ConnectionManager private static readonly Action _createdNewConnection = LoggerMessage.Define(LogLevel.Debug, new EventId(0, nameof(CreatedNewConnection)), "{time}: ConnectionId {connectionId}: New connection created."); private static readonly Action _removedConnection = LoggerMessage.Define(LogLevel.Debug, new EventId(1, nameof(RemovedConnection)), "{time}: ConnectionId {connectionId}: Removing connection from the list of connections."); private static readonly Action _failedDispose = LoggerMessage.Define(LogLevel.Error, new EventId(2, nameof(FailedDispose)), "{time}: ConnectionId {connectionId}: Failed disposing connection."); private static readonly Action _connectionReset = LoggerMessage.Define(LogLevel.Trace, new EventId(3, nameof(ConnectionReset)), "{time}: ConnectionId {connectionId}: Connection was reset."); public static void CreatedNewConnection(this ILogger logger, string connectionId) { if (logger.IsEnabled(LogLevel.Debug)) { _createdNewConnection(logger, DateTime.Now, connectionId, null); } } public static void RemovedConnection(this ILogger logger, string connectionId) { if (logger.IsEnabled(LogLevel.Debug)) { _removedConnection(logger, DateTime.Now, connectionId, null); } } public static void FailedDispose(this ILogger logger, string connectionId, Exception exception) { if (logger.IsEnabled(LogLevel.Error)) { _failedDispose(logger, DateTime.Now, connectionId, exception); } } public static void ConnectionReset(this ILogger logger, string connectionId, Exception exception) { if (logger.IsEnabled(LogLevel.Trace)) { _connectionReset(logger, DateTime.Now, connectionId, exception); } } } }