// 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.AspNetCore.Connections; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Sockets.Client.Http { public partial class HttpConnection { private static class Log { private static readonly Action _starting = LoggerMessage.Define(LogLevel.Debug, new EventId(1, "Starting"), "Starting HttpConnection."); private static readonly Action _skippingStart = LoggerMessage.Define(LogLevel.Debug, new EventId(2, "SkippingStart"), "Skipping start, connection is already started."); private static readonly Action _started = LoggerMessage.Define(LogLevel.Information, new EventId(3, "Started"), "HttpConnection Started."); private static readonly Action _disposingHttpConnection = LoggerMessage.Define(LogLevel.Debug, new EventId(4, "DisposingHttpConnection"), "Disposing HttpConnection."); private static readonly Action _skippingDispose = LoggerMessage.Define(LogLevel.Debug, new EventId(5, "SkippingDispose"), "Skipping dispose, connection is already disposed."); private static readonly Action _disposed = LoggerMessage.Define(LogLevel.Information, new EventId(6, "Disposed"), "HttpConnection Disposed."); private static readonly Action _startingTransport = LoggerMessage.Define(LogLevel.Debug, new EventId(7, "StartingTransport"), "Starting transport '{Transport}' with Url: {Url}."); private static readonly Action _establishingConnection = LoggerMessage.Define(LogLevel.Debug, new EventId(8, "EstablishingConnection"), "Establishing connection with server at '{Url}'."); private static readonly Action _connectionEstablished = LoggerMessage.Define(LogLevel.Debug, new EventId(9, "Established"), "Established connection '{ConnectionId}' with the server."); private static readonly Action _errorWithNegotiation = LoggerMessage.Define(LogLevel.Error, new EventId(10, "ErrorWithNegotiation"), "Failed to start connection. Error getting negotiation response from '{Url}'."); private static readonly Action _errorStartingTransport = LoggerMessage.Define(LogLevel.Error, new EventId(11, "ErrorStartingTransport"), "Failed to start connection. Error starting transport '{Transport}'."); private static readonly Action _transportNotSupported = LoggerMessage.Define(LogLevel.Debug, new EventId(12, "TransportNotSupported"), "Skipping transport {TransportName} because it is not supported by this client."); private static readonly Action _transportDoesNotSupportTransferFormat = LoggerMessage.Define(LogLevel.Debug, new EventId(13, "TransportDoesNotSupportTransferFormat"), "Skipping transport {TransportName} because it does not support the requested transfer format '{TransferFormat}'."); private static readonly Action _transportDisabledByClient = LoggerMessage.Define(LogLevel.Debug, new EventId(14, "TransportDisabledByClient"), "Skipping transport {TransportName} because it was disabled by the client."); private static readonly Action _transportFailed = LoggerMessage.Define(LogLevel.Debug, new EventId(15, "TransportFailed"), "Skipping transport {TransportName} because it failed to initialize."); private static readonly Action _webSocketsNotSupportedByOperatingSystem = LoggerMessage.Define(LogLevel.Debug, new EventId(16, "WebSocketsNotSupportedByOperatingSystem"), "Skipping WebSockets because they are not supported by the operating system."); private static readonly Action _transportThrewExceptionOnStop = LoggerMessage.Define(LogLevel.Error, new EventId(17, "TransportThrewExceptionOnStop"), "The transport threw an exception while stopping."); public static void Starting(ILogger logger) { _starting(logger, null); } public static void SkippingStart(ILogger logger) { _skippingStart(logger, null); } public static void Started(ILogger logger) { _started(logger, null); } public static void DisposingHttpConnection(ILogger logger) { _disposingHttpConnection(logger, null); } public static void SkippingDispose(ILogger logger) { _skippingDispose(logger, null); } public static void Disposed(ILogger logger) { _disposed(logger, null); } public static void StartingTransport(ILogger logger, TransportType transportType, Uri url) { if (logger.IsEnabled(LogLevel.Debug)) { _startingTransport(logger, transportType.ToString(), url, null); } } public static void EstablishingConnection(ILogger logger, Uri url) { _establishingConnection(logger, url, null); } public static void ConnectionEstablished(ILogger logger, string connectionId) { _connectionEstablished(logger, connectionId, null); } public static void ErrorWithNegotiation(ILogger logger, Uri url, Exception exception) { _errorWithNegotiation(logger, url, exception); } public static void ErrorStartingTransport(ILogger logger, ITransport transport, Exception exception) { if (logger.IsEnabled(LogLevel.Error)) { _errorStartingTransport(logger, transport.GetType().Name, exception); } } public static void TransportNotSupported(ILogger logger, string transport) { _transportNotSupported(logger, transport, null); } public static void TransportDoesNotSupportTransferFormat(ILogger logger, TransportType transport, TransferFormat transferFormat) { if (logger.IsEnabled(LogLevel.Debug)) { _transportDoesNotSupportTransferFormat(logger, transport.ToString(), transferFormat.ToString(), null); } } public static void TransportDisabledByClient(ILogger logger, TransportType transport) { if (logger.IsEnabled(LogLevel.Debug)) { _transportDisabledByClient(logger, transport.ToString(), null); } } public static void TransportFailed(ILogger logger, TransportType transport, Exception ex) { if (logger.IsEnabled(LogLevel.Debug)) { _transportFailed(logger, transport.ToString(), ex); } } public static void WebSocketsNotSupportedByOperatingSystem(ILogger logger) { _webSocketsNotSupportedByOperatingSystem(logger, null); } public static void TransportThrewExceptionOnStop(ILogger logger, Exception ex) { _transportThrewExceptionOnStop(logger, ex); } } } }