From 786980bc3fc806c0c457d4500f209d52dba4ea09 Mon Sep 17 00:00:00 2001 From: Andrew Stanton-Nurse Date: Thu, 21 Sep 2017 17:36:50 -0700 Subject: [PATCH] add names to EventIds used by logger extensions (#927) --- .../Internal/SignalRClientLoggerExtensions.cs | 62 ++++++------ .../Internal/SignalRCoreLoggerExtensions.cs | 28 +++--- .../HttpConnection.cs | 6 +- .../Internal/SocketClientLoggerExtensions.cs | 96 +++++++++---------- .../Internal/SocketHttpLoggerExtensions.cs | 58 +++++------ .../Internal/SocketLoggerExtensions.cs | 10 +- 6 files changed, 130 insertions(+), 130 deletions(-) diff --git a/src/Microsoft.AspNetCore.SignalR.Client.Core/Internal/SignalRClientLoggerExtensions.cs b/src/Microsoft.AspNetCore.SignalR.Client.Core/Internal/SignalRClientLoggerExtensions.cs index 08068fc3b5..037840b0cf 100644 --- a/src/Microsoft.AspNetCore.SignalR.Client.Core/Internal/SignalRClientLoggerExtensions.cs +++ b/src/Microsoft.AspNetCore.SignalR.Client.Core/Internal/SignalRClientLoggerExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; @@ -11,97 +11,97 @@ namespace Microsoft.AspNetCore.SignalR.Client.Internal { // Category: HubConnection private static readonly Action _preparingNonBlockingInvocation = - LoggerMessage.Define(LogLevel.Trace, 0, "Preparing non-blocking invocation '{invocationId}' of '{target}', with {argumentCount} argument(s)."); + LoggerMessage.Define(LogLevel.Trace, new EventId(0, nameof(PreparingNonBlockingInvocation)), "Preparing non-blocking invocation '{invocationId}' of '{target}', with {argumentCount} argument(s)."); private static readonly Action _preparingBlockingInvocation = - LoggerMessage.Define(LogLevel.Trace, 1, "Preparing blocking invocation '{invocationId}' of '{target}', with return type '{returnType}' and {argumentCount} argument(s)."); + LoggerMessage.Define(LogLevel.Trace, new EventId(1, nameof(PreparingBlockingInvocation)), "Preparing blocking invocation '{invocationId}' of '{target}', with return type '{returnType}' and {argumentCount} argument(s)."); private static readonly Action _registerInvocation = - LoggerMessage.Define(LogLevel.Debug, 2, "Registering Invocation ID '{invocationId}' for tracking."); + LoggerMessage.Define(LogLevel.Debug, new EventId(2, nameof(RegisterInvocation)), "Registering Invocation ID '{invocationId}' for tracking."); private static readonly Action _issueInvocation = - LoggerMessage.Define(LogLevel.Trace, 3, "Issuing Invocation '{invocationId}': {returnType} {methodName}({args})."); + LoggerMessage.Define(LogLevel.Trace, new EventId(3, nameof(IssueInvocation)), "Issuing Invocation '{invocationId}': {returnType} {methodName}({args})."); private static readonly Action _sendInvocation = - LoggerMessage.Define(LogLevel.Debug, 4, "Sending Invocation '{invocationId}'."); + LoggerMessage.Define(LogLevel.Debug, new EventId(4, nameof(SendInvocation)), "Sending Invocation '{invocationId}'."); private static readonly Action _sendInvocationCompleted = - LoggerMessage.Define(LogLevel.Debug, 5, "Sending Invocation '{invocationId}' completed."); + LoggerMessage.Define(LogLevel.Debug, new EventId(5, nameof(SendInvocationCompleted)), "Sending Invocation '{invocationId}' completed."); private static readonly Action _sendInvocationFailed = - LoggerMessage.Define(LogLevel.Error, 6, "Sending Invocation '{invocationId}' failed."); + LoggerMessage.Define(LogLevel.Error, new EventId(6, nameof(SendInvocationFailed)), "Sending Invocation '{invocationId}' failed."); private static readonly Action _receivedInvocation = - LoggerMessage.Define(LogLevel.Trace, 7, "Received Invocation '{invocationId}': {methodName}({args})."); + LoggerMessage.Define(LogLevel.Trace, new EventId(7, nameof(ReceivedInvocation)), "Received Invocation '{invocationId}': {methodName}({args})."); private static readonly Action _dropCompletionMessage = - LoggerMessage.Define(LogLevel.Warning, 8, "Dropped unsolicited Completion message for invocation '{invocationId}'."); + LoggerMessage.Define(LogLevel.Warning, new EventId(8, nameof(DropCompletionMessage)), "Dropped unsolicited Completion message for invocation '{invocationId}'."); private static readonly Action _dropStreamMessage = - LoggerMessage.Define(LogLevel.Warning, 9, "Dropped unsolicited StreamItem message for invocation '{invocationId}'."); + LoggerMessage.Define(LogLevel.Warning, new EventId(9, nameof(DropStreamMessage)), "Dropped unsolicited StreamItem message for invocation '{invocationId}'."); private static readonly Action _shutdownConnection = - LoggerMessage.Define(LogLevel.Trace, 10, "Shutting down connection."); + LoggerMessage.Define(LogLevel.Trace, new EventId(10, nameof(ShutdownConnection)), "Shutting down connection."); private static readonly Action _shutdownWithError = - LoggerMessage.Define(LogLevel.Error, 11, "Connection is shutting down due to an error."); + LoggerMessage.Define(LogLevel.Error, new EventId(11, nameof(ShutdownWithError)), "Connection is shutting down due to an error."); private static readonly Action _removeInvocation = - LoggerMessage.Define(LogLevel.Trace, 12, "Removing pending invocation {invocationId}."); + LoggerMessage.Define(LogLevel.Trace, new EventId(12, nameof(RemoveInvocation)), "Removing pending invocation {invocationId}."); private static readonly Action _missingHandler = - LoggerMessage.Define(LogLevel.Warning, 13, "Failed to find handler for '{target}' method."); + LoggerMessage.Define(LogLevel.Warning, new EventId(13, nameof(MissingHandler)), "Failed to find handler for '{target}' method."); private static readonly Action _receivedStreamItem = - LoggerMessage.Define(LogLevel.Trace, 14, "Received StreamItem for Invocation {invocationId}."); + LoggerMessage.Define(LogLevel.Trace, new EventId(14, nameof(ReceivedStreamItem)), "Received StreamItem for Invocation {invocationId}."); private static readonly Action _cancelingStreamItem = - LoggerMessage.Define(LogLevel.Trace, 15, "Canceling dispatch of StreamItem message for Invocation {invocationId}. The invocation was canceled."); + LoggerMessage.Define(LogLevel.Trace, new EventId(15, nameof(CancelingStreamItem)), "Canceling dispatch of StreamItem message for Invocation {invocationId}. The invocation was canceled."); private static readonly Action _receivedStreamItemAfterClose = - LoggerMessage.Define(LogLevel.Warning, 16, "Invocation {invocationId} received stream item after channel was closed."); + LoggerMessage.Define(LogLevel.Warning, new EventId(16, nameof(ReceivedStreamItemAfterClose)), "Invocation {invocationId} received stream item after channel was closed."); private static readonly Action _receivedInvocationCompletion = - LoggerMessage.Define(LogLevel.Trace, 17, "Received Completion for Invocation {invocationId}."); + LoggerMessage.Define(LogLevel.Trace, new EventId(17, nameof(ReceivedInvocationCompletion)), "Received Completion for Invocation {invocationId}."); private static readonly Action _cancelingCompletion = - LoggerMessage.Define(LogLevel.Trace, 18, "Canceling dispatch of Completion message for Invocation {invocationId}. The invocation was canceled."); + LoggerMessage.Define(LogLevel.Trace, new EventId(18, nameof(CancelingCompletion)), "Canceling dispatch of Completion message for Invocation {invocationId}. The invocation was canceled."); private static readonly Action _invokeAfterTermination = - LoggerMessage.Define(LogLevel.Error, 19, "Invoke for Invocation '{invocationId}' was called after the connection was terminated."); + LoggerMessage.Define(LogLevel.Error, new EventId(19, nameof(InvokeAfterTermination)), "Invoke for Invocation '{invocationId}' was called after the connection was terminated."); private static readonly Action _invocationAlreadyInUse = - LoggerMessage.Define(LogLevel.Critical, 20, "Invocation ID '{invocationId}' is already in use."); + LoggerMessage.Define(LogLevel.Critical, new EventId(20, nameof(InvocationAlreadyInUse)), "Invocation ID '{invocationId}' is already in use."); private static readonly Action _receivedUnexpectedResponse = - LoggerMessage.Define(LogLevel.Error, 21, "Unsolicited response received for invocation '{invocationId}'."); + LoggerMessage.Define(LogLevel.Error, new EventId(21, nameof(ReceivedUnexpectedResponse)), "Unsolicited response received for invocation '{invocationId}'."); private static readonly Action _hubProtocol = - LoggerMessage.Define(LogLevel.Information, 22, "Using HubProtocol '{protocol}'."); + LoggerMessage.Define(LogLevel.Information, new EventId(22, nameof(HubProtocol)), "Using HubProtocol '{protocol}'."); // Category: Streaming and NonStreaming private static readonly Action _invocationCreated = - LoggerMessage.Define(LogLevel.Trace, 0, "Invocation {invocationId} created."); + LoggerMessage.Define(LogLevel.Trace, new EventId(0, nameof(InvocationCreated)), "Invocation {invocationId} created."); private static readonly Action _invocationDisposed = - LoggerMessage.Define(LogLevel.Trace, 1, "Invocation {invocationId} disposed."); + LoggerMessage.Define(LogLevel.Trace, new EventId(1, nameof(InvocationDisposed)), "Invocation {invocationId} disposed."); private static readonly Action _invocationCompleted = - LoggerMessage.Define(LogLevel.Trace, 2, "Invocation {invocationId} marked as completed."); + LoggerMessage.Define(LogLevel.Trace, new EventId(2, nameof(InvocationCompleted)), "Invocation {invocationId} marked as completed."); private static readonly Action _invocationFailed = - LoggerMessage.Define(LogLevel.Trace, 3, "Invocation {invocationId} marked as failed."); + LoggerMessage.Define(LogLevel.Trace, new EventId(3, nameof(InvocationFailed)), "Invocation {invocationId} marked as failed."); // Category: Streaming private static readonly Action _receivedUnexpectedComplete = - LoggerMessage.Define(LogLevel.Error, 4, "Invocation {invocationId} received a completion result, but was invoked as a streaming invocation."); + LoggerMessage.Define(LogLevel.Error, new EventId(4, nameof(ReceivedUnexpectedComplete)), "Invocation {invocationId} received a completion result, but was invoked as a streaming invocation."); private static readonly Action _errorWritingStreamItem = - LoggerMessage.Define(LogLevel.Error, 5, "Invocation {invocationId} caused an error trying to write a stream item."); + LoggerMessage.Define(LogLevel.Error, new EventId(5, nameof(ErrorWritingStreamItem)), "Invocation {invocationId} caused an error trying to write a stream item."); // Category: NonStreaming private static readonly Action _streamItemOnNonStreamInvocation = - LoggerMessage.Define(LogLevel.Error, 4, "Invocation {invocationId} received stream item but was invoked as a non-streamed invocation."); + LoggerMessage.Define(LogLevel.Error, new EventId(4, nameof(StreamItemOnNonStreamInvocation)), "Invocation {invocationId} received stream item but was invoked as a non-streamed invocation."); public static void PreparingNonBlockingInvocation(this ILogger logger, string invocationId, string target, int count) { diff --git a/src/Microsoft.AspNetCore.SignalR.Core/Internal/SignalRCoreLoggerExtensions.cs b/src/Microsoft.AspNetCore.SignalR.Core/Internal/SignalRCoreLoggerExtensions.cs index b02f898834..ee41f75f82 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/Internal/SignalRCoreLoggerExtensions.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/Internal/SignalRCoreLoggerExtensions.cs @@ -11,43 +11,43 @@ namespace Microsoft.AspNetCore.SignalR.Core.Internal { // Category: HubEndPoint private static readonly Action _usingHubProtocol = - LoggerMessage.Define(LogLevel.Information, 0, "Using HubProtocol '{protocol}'."); + LoggerMessage.Define(LogLevel.Information, new EventId(0, nameof(UsingHubProtocol)), "Using HubProtocol '{protocol}'."); private static readonly Action _negotiateCanceled = - LoggerMessage.Define(LogLevel.Debug, 1, "Negotiate was canceled."); + LoggerMessage.Define(LogLevel.Debug, new EventId(1, nameof(NegotiateCanceled)), "Negotiate was canceled."); private static readonly Action _errorProcessingRequest = - LoggerMessage.Define(LogLevel.Error, 2, "Error when processing requests."); + LoggerMessage.Define(LogLevel.Error, new EventId(2, nameof(ErrorProcessingRequest)), "Error when processing requests."); private static readonly Action _errorInvokingHubMethod = - LoggerMessage.Define(LogLevel.Error, 3, "Error when invoking '{hubMethod}' on hub."); + LoggerMessage.Define(LogLevel.Error, new EventId(3, nameof(ErrorInvokingHubMethod)), "Error when invoking '{hubMethod}' on hub."); private static readonly Action _receivedHubInvocation = - LoggerMessage.Define(LogLevel.Debug, 4, "Received hub invocation: {invocationMessage}."); + LoggerMessage.Define(LogLevel.Debug, new EventId(4, nameof(ReceivedHubInvocation)), "Received hub invocation: {invocationMessage}."); private static readonly Action _unsupportedMessageReceived = - LoggerMessage.Define(LogLevel.Error, 5, "Received unsupported message of type '{messageType}'."); + LoggerMessage.Define(LogLevel.Error, new EventId(5, nameof(UnsupportedMessageReceived)), "Received unsupported message of type '{messageType}'."); private static readonly Action _unknownHubMethod = - LoggerMessage.Define(LogLevel.Error, 6, "Unknown hub method '{hubMethod}'."); + LoggerMessage.Define(LogLevel.Error, new EventId(6, nameof(UnknownHubMethod)), "Unknown hub method '{hubMethod}'."); private static readonly Action _outboundChannelClosed = - LoggerMessage.Define(LogLevel.Warning, 7, "Outbound channel was closed while trying to write hub message."); + LoggerMessage.Define(LogLevel.Warning, new EventId(7, nameof(OutboundChannelClosed)), "Outbound channel was closed while trying to write hub message."); private static readonly Action _hubMethodNotAuthorized = - LoggerMessage.Define(LogLevel.Debug, 8, "Failed to invoke '{hubMethod}' because user is unauthorized."); + LoggerMessage.Define(LogLevel.Debug, new EventId(8, nameof(HubMethodNotAuthorized)), "Failed to invoke '{hubMethod}' because user is unauthorized."); private static readonly Action _streamingResult = - LoggerMessage.Define(LogLevel.Trace, 9, "{invocationId}: Streaming result of type '{resultType}'."); + LoggerMessage.Define(LogLevel.Trace, new EventId(9, nameof(StreamingResult)), "{invocationId}: Streaming result of type '{resultType}'."); private static readonly Action _sendingResult = - LoggerMessage.Define(LogLevel.Trace, 10, "{invocationId}: Sending result of type '{resultType}'."); + LoggerMessage.Define(LogLevel.Trace, new EventId(10, nameof(SendingResult)), "{invocationId}: Sending result of type '{resultType}'."); private static readonly Action _failedInvokingHubMethod = - LoggerMessage.Define(LogLevel.Error, 11, "Failed to invoke hub method '{hubMethod}'."); + LoggerMessage.Define(LogLevel.Error, new EventId(11, nameof(FailedInvokingHubMethod)), "Failed to invoke hub method '{hubMethod}'."); private static readonly Action _hubMethodBound = - LoggerMessage.Define(LogLevel.Trace, 12, "Hub method '{hubMethod}' is bound."); + LoggerMessage.Define(LogLevel.Trace, new EventId(12, nameof(HubMethodBound)), "Hub method '{hubMethod}' is bound."); public static void UsingHubProtocol(this ILogger logger, string hubProtocol) { @@ -114,4 +114,4 @@ namespace Microsoft.AspNetCore.SignalR.Core.Internal _hubMethodBound(logger, hubMethod, null); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.cs index e43015ca4e..50a9fdba74 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.cs @@ -169,7 +169,7 @@ namespace Microsoft.AspNetCore.Sockets.Client } catch (Exception ex) { - _logger.ExceptionThrownFromEventHandler(_connectionId, nameof(Connected), ex); + _logger.ExceptionThrownFromHandler(_connectionId, nameof(Connected), ex); } } }); @@ -205,7 +205,7 @@ namespace Microsoft.AspNetCore.Sockets.Client } catch (Exception ex) { - _logger.ExceptionThrownFromEventHandler(_connectionId, nameof(Closed), ex); + _logger.ExceptionThrownFromHandler(_connectionId, nameof(Closed), ex); } } }); @@ -366,7 +366,7 @@ namespace Microsoft.AspNetCore.Sockets.Client } catch (Exception ex) { - _logger.ExceptionThrownFromEventHandler(_connectionId, nameof(Received), ex); + _logger.ExceptionThrownFromHandler(_connectionId, nameof(Received), ex); } } }); diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/Internal/SocketClientLoggerExtensions.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/Internal/SocketClientLoggerExtensions.cs index dfec2e0726..153fed65ef 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/Internal/SocketClientLoggerExtensions.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/Internal/SocketClientLoggerExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; @@ -11,147 +11,147 @@ namespace Microsoft.AspNetCore.Sockets.Client.Internal { // Category: Shared with LongPollingTransport, WebSocketsTransport and ServerSentEventsTransport private static readonly Action _startTransport = - LoggerMessage.Define(LogLevel.Information, 0, "{time}: Connection Id {connectionId}: Starting transport. Transfer mode: {transferMode}."); + LoggerMessage.Define(LogLevel.Information, new EventId(0, nameof(StartTransport)), "{time}: Connection Id {connectionId}: Starting transport. Transfer mode: {transferMode}."); private static readonly Action _transportStopped = - LoggerMessage.Define(LogLevel.Debug, 1, "{time}: Connection Id {connectionId}: Transport stopped."); + LoggerMessage.Define(LogLevel.Debug, new EventId(1, nameof(TransportStopped)), "{time}: Connection Id {connectionId}: Transport stopped."); private static readonly Action _startReceive = - LoggerMessage.Define(LogLevel.Debug, 2, "{time}: Connection Id {connectionId}: Starting receive loop."); + LoggerMessage.Define(LogLevel.Debug, new EventId(2, nameof(StartReceive)), "{time}: Connection Id {connectionId}: Starting receive loop."); private static readonly Action _receiveStopped = - LoggerMessage.Define(LogLevel.Debug, 3, "{time}: Connection Id {connectionId}: Receive loop stopped."); + LoggerMessage.Define(LogLevel.Debug, new EventId(3, nameof(ReceiveStopped)), "{time}: Connection Id {connectionId}: Receive loop stopped."); private static readonly Action _receiveCanceled = - LoggerMessage.Define(LogLevel.Debug, 4, "{time}: Connection Id {connectionId}: Receive loop canceled."); + LoggerMessage.Define(LogLevel.Debug, new EventId(4, nameof(ReceiveCanceled)), "{time}: Connection Id {connectionId}: Receive loop canceled."); private static readonly Action _transportStopping = - LoggerMessage.Define(LogLevel.Information, 5, "{time}: Connection Id {connectionId}: Transport is stopping."); + LoggerMessage.Define(LogLevel.Information, new EventId(5, nameof(TransportStopping)), "{time}: Connection Id {connectionId}: Transport is stopping."); private static readonly Action _sendStarted = - LoggerMessage.Define(LogLevel.Debug, 6, "{time}: Connection Id {connectionId}: Starting the send loop."); + LoggerMessage.Define(LogLevel.Debug, new EventId(6, nameof(SendStarted)), "{time}: Connection Id {connectionId}: Starting the send loop."); private static readonly Action _sendStopped = - LoggerMessage.Define(LogLevel.Debug, 7, "{time}: Connection Id {connectionId}: Send loop stopped."); + LoggerMessage.Define(LogLevel.Debug, new EventId(7, nameof(SendStopped)), "{time}: Connection Id {connectionId}: Send loop stopped."); private static readonly Action _sendCanceled = - LoggerMessage.Define(LogLevel.Debug, 8, "{time}: Connection Id {connectionId}: Send loop canceled."); + LoggerMessage.Define(LogLevel.Debug, new EventId(8, nameof(SendCanceled)), "{time}: Connection Id {connectionId}: Send loop canceled."); // Category: WebSocketsTransport private static readonly Action _webSocketClosed = - LoggerMessage.Define(LogLevel.Information, 9, "{time}: Connection Id {connectionId}: Websocket closed by the server. Close status {closeStatus}."); + LoggerMessage.Define(LogLevel.Information, new EventId(9, nameof(WebSocketClosed)), "{time}: Connection Id {connectionId}: Websocket closed by the server. Close status {closeStatus}."); private static readonly Action _messageReceived = - LoggerMessage.Define(LogLevel.Debug, 10, "{time}: Connection Id {connectionId}: Message received. Type: {messageType}, size: {count}, EndOfMessage: {endOfMessage}."); + LoggerMessage.Define(LogLevel.Debug, new EventId(10, nameof(MessageReceived)), "{time}: Connection Id {connectionId}: Message received. Type: {messageType}, size: {count}, EndOfMessage: {endOfMessage}."); private static readonly Action _messageToApp = - LoggerMessage.Define(LogLevel.Debug, 11, "{time}: Connection Id {connectionId}: Passing message to application. Payload size: {count}."); + LoggerMessage.Define(LogLevel.Debug, new EventId(11, nameof(MessageToApp)), "{time}: Connection Id {connectionId}: Passing message to application. Payload size: {count}."); private static readonly Action _receivedFromApp = - LoggerMessage.Define(LogLevel.Debug, 12, "{time}: Connection Id {connectionId}: Received message from application. Payload size: {count}."); + LoggerMessage.Define(LogLevel.Debug, new EventId(12, nameof(ReceivedFromApp)), "{time}: Connection Id {connectionId}: Received message from application. Payload size: {count}."); private static readonly Action _sendMessageCanceled = - LoggerMessage.Define(LogLevel.Information, 13, "{time}: Connection Id {connectionId}: Sending a message canceled."); + LoggerMessage.Define(LogLevel.Information, new EventId(13, nameof(SendMessageCanceled)), "{time}: Connection Id {connectionId}: Sending a message canceled."); private static readonly Action _errorSendingMessage = - LoggerMessage.Define(LogLevel.Error, 14, "{time}: Connection Id {connectionId}: Error while sending a message."); + LoggerMessage.Define(LogLevel.Error, new EventId(14, nameof(ErrorSendingMessage)), "{time}: Connection Id {connectionId}: Error while sending a message."); private static readonly Action _closingWebSocket = - LoggerMessage.Define(LogLevel.Information, 15, "{time}: Connection Id {connectionId}: Closing WebSocket."); + LoggerMessage.Define(LogLevel.Information, new EventId(15, nameof(ClosingWebSocket)), "{time}: Connection Id {connectionId}: Closing WebSocket."); private static readonly Action _closingWebSocketFailed = - LoggerMessage.Define(LogLevel.Information, 16, "{time}: Connection Id {connectionId}: Closing webSocket failed."); + LoggerMessage.Define(LogLevel.Information, new EventId(16, nameof(ClosingWebSocketFailed)), "{time}: Connection Id {connectionId}: Closing webSocket failed."); private static readonly Action _cancelMessage = - LoggerMessage.Define(LogLevel.Debug, 17, "{time}: Connection Id {connectionId}: Canceled passing message to application."); + LoggerMessage.Define(LogLevel.Debug, new EventId(17, nameof(CancelMessage)), "{time}: Connection Id {connectionId}: Canceled passing message to application."); // Category: ServerSentEventsTransport and LongPollingTransport private static readonly Action _sendingMessages = - LoggerMessage.Define(LogLevel.Debug, 9, "{time}: Connection Id {connectionId}: Sending {count} message(s) to the server using url: {url}."); + LoggerMessage.Define(LogLevel.Debug, new EventId(9, nameof(SendingMessages)), "{time}: Connection Id {connectionId}: Sending {count} message(s) to the server using url: {url}."); private static readonly Action _sentSuccessfully = - LoggerMessage.Define(LogLevel.Debug, 10, "{time}: Connection Id {connectionId}: Message(s) sent successfully."); + LoggerMessage.Define(LogLevel.Debug, new EventId(10, nameof(SentSuccessfully)), "{time}: Connection Id {connectionId}: Message(s) sent successfully."); private static readonly Action _noMessages = - LoggerMessage.Define(LogLevel.Debug, 11, "{time}: Connection Id {connectionId}: No messages in batch to send."); + LoggerMessage.Define(LogLevel.Debug, new EventId(11, nameof(NoMessages)), "{time}: Connection Id {connectionId}: No messages in batch to send."); private static readonly Action _errorSending = - LoggerMessage.Define(LogLevel.Error, 12, "{time}: Connection Id {connectionId}: Error while sending to '{url}'."); + LoggerMessage.Define(LogLevel.Error, new EventId(12, nameof(ErrorSending)), "{time}: Connection Id {connectionId}: Error while sending to '{url}'."); // Category: ServerSentEventsTransport private static readonly Action _eventStreamEnded = - LoggerMessage.Define(LogLevel.Debug, 13, "{time}: Connection Id {connectionId}: Server-Sent Event Stream ended."); + LoggerMessage.Define(LogLevel.Debug, new EventId(13, nameof(EventStreamEnded)), "{time}: Connection Id {connectionId}: Server-Sent Event Stream ended."); // Category: LongPollingTransport private static readonly Action _closingConnection = - LoggerMessage.Define(LogLevel.Debug, 13, "{time}: Connection Id {connectionId}: The server is closing the connection."); + LoggerMessage.Define(LogLevel.Debug, new EventId(13, nameof(ClosingConnection)), "{time}: Connection Id {connectionId}: The server is closing the connection."); private static readonly Action _receivedMessages = - LoggerMessage.Define(LogLevel.Debug, 14, "{time}: Connection Id {connectionId}: Received messages from the server."); + LoggerMessage.Define(LogLevel.Debug, new EventId(14, nameof(ReceivedMessages)), "{time}: Connection Id {connectionId}: Received messages from the server."); private static readonly Action _errorPolling = - LoggerMessage.Define(LogLevel.Error, 15, "{time}: Connection Id {connectionId}: Error while polling '{pollUrl}'."); + LoggerMessage.Define(LogLevel.Error, new EventId(15, nameof(ErrorPolling)), "{time}: Connection Id {connectionId}: Error while polling '{pollUrl}'."); // Category: HttpConnection private static readonly Action _httpConnectionStarting = - LoggerMessage.Define(LogLevel.Debug, 0, "{time}: Starting connection."); + LoggerMessage.Define(LogLevel.Debug, new EventId(0, nameof(HttpConnectionStarting)), "{time}: Starting connection."); private static readonly Action _httpConnectionClosed = - LoggerMessage.Define(LogLevel.Debug, 1, "{time}: Connection Id {connectionId}: Connection was closed from a different thread."); + LoggerMessage.Define(LogLevel.Debug, new EventId(1, nameof(HttpConnectionClosed)), "{time}: Connection Id {connectionId}: Connection was closed from a different thread."); private static readonly Action _startingTransport = - LoggerMessage.Define(LogLevel.Debug, 2, "{time}: Connection Id {connectionId}: Starting transport '{transport}' with Url: {url}."); + LoggerMessage.Define(LogLevel.Debug, new EventId(2, nameof(StartingTransport)), "{time}: Connection Id {connectionId}: Starting transport '{transport}' with Url: {url}."); private static readonly Action _raiseConnected = - LoggerMessage.Define(LogLevel.Debug, 3, "{time}: Connection Id {connectionId}: Raising Connected event."); + LoggerMessage.Define(LogLevel.Debug, new EventId(3, nameof(RaiseConnected)), "{time}: Connection Id {connectionId}: Raising Connected event."); private static readonly Action _processRemainingMessages = - LoggerMessage.Define(LogLevel.Debug, 4, "{time}: Connection Id {connectionId}: Ensuring all outstanding messages are processed."); + LoggerMessage.Define(LogLevel.Debug, new EventId(4, nameof(ProcessRemainingMessages)), "{time}: Connection Id {connectionId}: Ensuring all outstanding messages are processed."); private static readonly Action _drainEvents = - LoggerMessage.Define(LogLevel.Debug, 5, "{time}: Connection Id {connectionId}: Draining event queue."); + LoggerMessage.Define(LogLevel.Debug, new EventId(5, nameof(DrainEvents)), "{time}: Connection Id {connectionId}: Draining event queue."); private static readonly Action _raiseClosed = - LoggerMessage.Define(LogLevel.Debug, 6, "{time}: Connection Id {connectionId}: Raising Closed event."); + LoggerMessage.Define(LogLevel.Debug, new EventId(6, nameof(RaiseClosed)), "{time}: Connection Id {connectionId}: Raising Closed event."); private static readonly Action _establishingConnection = - LoggerMessage.Define(LogLevel.Debug, 7, "{time}: Establishing Connection at: {url}."); + LoggerMessage.Define(LogLevel.Debug, new EventId(7, nameof(EstablishingConnection)), "{time}: Establishing Connection at: {url}."); private static readonly Action _errorWithNegotiation = - LoggerMessage.Define(LogLevel.Error, 8, "{time}: Failed to start connection. Error getting negotiation response from '{url}'."); + LoggerMessage.Define(LogLevel.Error, new EventId(8, nameof(ErrorWithNegotiation)), "{time}: Failed to start connection. Error getting negotiation response from '{url}'."); private static readonly Action _errorStartingTransport = - LoggerMessage.Define(LogLevel.Error, 9, "{time}: Connection Id {connectionId}: Failed to start connection. Error starting transport '{transport}'."); + LoggerMessage.Define(LogLevel.Error, new EventId(9, nameof(ErrorStartingTransport)), "{time}: Connection Id {connectionId}: Failed to start connection. Error starting transport '{transport}'."); private static readonly Action _httpReceiveStarted = - LoggerMessage.Define(LogLevel.Trace, 10, "{time}: Connection Id {connectionId}: Beginning receive loop."); + LoggerMessage.Define(LogLevel.Trace, new EventId(10, nameof(HttpReceiveStarted)), "{time}: Connection Id {connectionId}: Beginning receive loop."); private static readonly Action _skipRaisingReceiveEvent = - LoggerMessage.Define(LogLevel.Debug, 11, "{time}: Connection Id {connectionId}: Message received but connection is not connected. Skipping raising Received event."); + LoggerMessage.Define(LogLevel.Debug, new EventId(11, nameof(SkipRaisingReceiveEvent)), "{time}: Connection Id {connectionId}: Message received but connection is not connected. Skipping raising Received event."); private static readonly Action _scheduleReceiveEvent = - LoggerMessage.Define(LogLevel.Debug, 12, "{time}: Connection Id {connectionId}: Scheduling raising Received event."); + LoggerMessage.Define(LogLevel.Debug, new EventId(12, nameof(ScheduleReceiveEvent)), "{time}: Connection Id {connectionId}: Scheduling raising Received event."); private static readonly Action _raiseReceiveEvent = - LoggerMessage.Define(LogLevel.Debug, 13, "{time}: Connection Id {connectionId}: Raising Received event."); + LoggerMessage.Define(LogLevel.Debug, new EventId(13, nameof(RaiseReceiveEvent)), "{time}: Connection Id {connectionId}: Raising Received event."); private static readonly Action _failedReadingMessage = - LoggerMessage.Define(LogLevel.Debug, 14, "{time}: Connection Id {connectionId}: Could not read message."); + LoggerMessage.Define(LogLevel.Debug, new EventId(14, nameof(FailedReadingMessage)), "{time}: Connection Id {connectionId}: Could not read message."); private static readonly Action _errorReceiving = - LoggerMessage.Define(LogLevel.Error, 15, "{time}: Connection Id {connectionId}: Error receiving message."); + LoggerMessage.Define(LogLevel.Error, new EventId(15, nameof(ErrorReceiving)), "{time}: Connection Id {connectionId}: Error receiving message."); private static readonly Action _endReceive = - LoggerMessage.Define(LogLevel.Trace, 16, "{time}: Connection Id {connectionId}: Ending receive loop."); + LoggerMessage.Define(LogLevel.Trace, new EventId(16, nameof(EndReceive)), "{time}: Connection Id {connectionId}: Ending receive loop."); private static readonly Action _sendingMessage = - LoggerMessage.Define(LogLevel.Debug, 17, "{time}: Connection Id {connectionId}: Sending message."); + LoggerMessage.Define(LogLevel.Debug, new EventId(17, nameof(SendingMessage)), "{time}: Connection Id {connectionId}: Sending message."); private static readonly Action _stoppingClient = - LoggerMessage.Define(LogLevel.Information, 18, "{time}: Connection Id {connectionId}: Stopping client."); + LoggerMessage.Define(LogLevel.Information, new EventId(18, nameof(StoppingClient)), "{time}: Connection Id {connectionId}: Stopping client."); private static readonly Action _exceptionThrownFromHandler = - LoggerMessage.Define(LogLevel.Error, 19, "{time}: Connection Id {connectionId}: An exception was thrown from the '{eventHandlerName}' event handler."); + LoggerMessage.Define(LogLevel.Error, new EventId(19, nameof(ExceptionThrownFromHandler)), "{time}: Connection Id {connectionId}: An exception was thrown from the '{eventHandlerName}' event handler."); public static void StartTransport(this ILogger logger, string connectionId, TransferMode transferMode) @@ -514,7 +514,7 @@ namespace Microsoft.AspNetCore.Sockets.Client.Internal } } - public static void ExceptionThrownFromEventHandler(this ILogger logger, string connectionId, string eventHandlerName, Exception exception) + public static void ExceptionThrownFromHandler(this ILogger logger, string connectionId, string eventHandlerName, Exception exception) { if (logger.IsEnabled(LogLevel.Error)) { diff --git a/src/Microsoft.AspNetCore.Sockets.Http/Internal/SocketHttpLoggerExtensions.cs b/src/Microsoft.AspNetCore.Sockets.Http/Internal/SocketHttpLoggerExtensions.cs index 6a506ad3de..06c1bb6c34 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/Internal/SocketHttpLoggerExtensions.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/Internal/SocketHttpLoggerExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; @@ -11,91 +11,91 @@ namespace Microsoft.AspNetCore.Sockets.Internal { // Category: LongPollingTransport private static readonly Action _longPolling204 = - LoggerMessage.Define(LogLevel.Information, 0, "{time}: Connection Id {connectionId}, Request Id {requestId}: Terminating Long Polling connection by sending 204 response."); + LoggerMessage.Define(LogLevel.Information, new EventId(0, nameof(LongPolling204)), "{time}: Connection Id {connectionId}, Request Id {requestId}: Terminating Long Polling connection by sending 204 response."); private static readonly Action _pollTimedOut = - LoggerMessage.Define(LogLevel.Information, 1, "{time}: Connection Id {connectionId}, Request Id {requestId}: Poll request timed out. Sending 200 response to connection."); + LoggerMessage.Define(LogLevel.Information, new EventId(1, nameof(PollTimedOut)), "{time}: Connection Id {connectionId}, Request Id {requestId}: Poll request timed out. Sending 200 response to connection."); private static readonly Action _longPollingWritingMessage = - LoggerMessage.Define(LogLevel.Debug, 2, "{time}: Connection Id {connectionId}, Request Id {requestId}: Writing a {count} byte message to connection."); + LoggerMessage.Define(LogLevel.Debug, new EventId(2, nameof(LongPollingWritingMessage)), "{time}: Connection Id {connectionId}, Request Id {requestId}: Writing a {count} byte message to connection."); private static readonly Action _longPollingDisconnected = - LoggerMessage.Define(LogLevel.Debug, 3, "{time}: Connection Id {connectionId}, Request Id {requestId}: Client disconnected from Long Polling endpoint for connection."); + LoggerMessage.Define(LogLevel.Debug, new EventId(3, nameof(LongPollingDisconnected)), "{time}: Connection Id {connectionId}, Request Id {requestId}: Client disconnected from Long Polling endpoint for connection."); private static readonly Action _longPollingTerminated = - LoggerMessage.Define(LogLevel.Error, 4, "{time}: Connection Id {connectionId}, Request Id {requestId}: Long Polling transport was terminated due to an error on connection."); + LoggerMessage.Define(LogLevel.Error, new EventId(4, nameof(LongPollingTerminated)), "{time}: Connection Id {connectionId}, Request Id {requestId}: Long Polling transport was terminated due to an error on connection."); // Category: HttpConnectionDispatcher private static readonly Action _connectionDisposed = - LoggerMessage.Define(LogLevel.Debug, 0, "{time}: Connection Id {connectionId} was disposed."); + LoggerMessage.Define(LogLevel.Debug, new EventId(0, nameof(ConnectionDisposed)), "{time}: Connection Id {connectionId} was disposed."); private static readonly Action _connectionAlreadyActive = - LoggerMessage.Define(LogLevel.Debug, 1, "{time}: Connection Id {connectionId} is already active via {requestId}."); + LoggerMessage.Define(LogLevel.Debug, new EventId(1, nameof(ConnectionAlreadyActive)), "{time}: Connection Id {connectionId} is already active via {requestId}."); private static readonly Action _pollCanceled = - LoggerMessage.Define(LogLevel.Debug, 2, "{time}: Previous poll canceled for {connectionId} on {requestId}."); + LoggerMessage.Define(LogLevel.Debug, new EventId(2, nameof(PollCanceled)), "{time}: Previous poll canceled for {connectionId} on {requestId}."); private static readonly Action _establishedConnection = - LoggerMessage.Define(LogLevel.Debug, 3, "{time}: Connection Id {connectionId}, Request Id {requestId}: Establishing new connection."); + LoggerMessage.Define(LogLevel.Debug, new EventId(3, nameof(EstablishedConnection)), "{time}: Connection Id {connectionId}, Request Id {requestId}: Establishing new connection."); private static readonly Action _resumingConnection = - LoggerMessage.Define(LogLevel.Debug, 4, "{time}: Connection Id {connectionId}, Request Id {requestId}: Resuming existing connection."); + LoggerMessage.Define(LogLevel.Debug, new EventId(4, nameof(ResumingConnection)), "{time}: Connection Id {connectionId}, Request Id {requestId}: Resuming existing connection."); private static readonly Action _receivedBytes = - LoggerMessage.Define(LogLevel.Debug, 5, "{time}: Connection Id {connectionId}: Received {count} bytes."); + LoggerMessage.Define(LogLevel.Debug, new EventId(5, nameof(ReceivedBytes)), "{time}: Connection Id {connectionId}: Received {count} bytes."); private static readonly Action _transportNotSupported = - LoggerMessage.Define(LogLevel.Debug, 6, "{time}: Connection Id {connectionId}: {transportType} transport not supported by this endpoint type."); + LoggerMessage.Define(LogLevel.Debug, new EventId(6, nameof(TransportNotSupported)), "{time}: Connection Id {connectionId}: {transportType} transport not supported by this endpoint type."); private static readonly Action _cannotChangeTransport = - LoggerMessage.Define(LogLevel.Debug, 7, "{time}: Connection Id {connectionId}: Cannot change transports mid-connection; currently using {transportType}, requesting {requestedTransport}."); + LoggerMessage.Define(LogLevel.Debug, new EventId(7, nameof(CannotChangeTransport)), "{time}: Connection Id {connectionId}: Cannot change transports mid-connection; currently using {transportType}, requesting {requestedTransport}."); private static readonly Action _negotiationRequest = - LoggerMessage.Define(LogLevel.Debug, 8, "{time}: Connection Id {connectionId}: Sending negotiation response."); + LoggerMessage.Define(LogLevel.Debug, new EventId(8, nameof(NegotiationRequest)), "{time}: Connection Id {connectionId}: Sending negotiation response."); // Category: WebSocketsTransport private static readonly Action _socketOpened = - LoggerMessage.Define(LogLevel.Information, 0, "{time}: Connection Id {connectionId}: Socket opened."); + LoggerMessage.Define(LogLevel.Information, new EventId(0, nameof(SocketOpened)), "{time}: Connection Id {connectionId}: Socket opened."); private static readonly Action _socketClosed = - LoggerMessage.Define(LogLevel.Information, 1, "{time}: Connection Id {connectionId}: Socket closed."); + LoggerMessage.Define(LogLevel.Information, new EventId(1, nameof(SocketClosed)), "{time}: Connection Id {connectionId}: Socket closed."); private static readonly Action _clientClosed = - LoggerMessage.Define(LogLevel.Debug, 2, "{time}: Connection Id {connectionId}: Client closed connection with status code '{status}' ({description}). Signaling end-of-input to application.."); + LoggerMessage.Define(LogLevel.Debug, new EventId(2, nameof(ClientClosed)), "{time}: Connection Id {connectionId}: Client closed connection with status code '{status}' ({description}). Signaling end-of-input to application.."); private static readonly Action _waitingForSend = - LoggerMessage.Define(LogLevel.Debug, 3, "{time}: Connection Id {connectionId}: Waiting for the application to finish sending data."); + LoggerMessage.Define(LogLevel.Debug, new EventId(3, nameof(WaitingForSend)), "{time}: Connection Id {connectionId}: Waiting for the application to finish sending data."); private static readonly Action _failedSending = - LoggerMessage.Define(LogLevel.Debug, 4, "{time}: Connection Id {connectionId}: Application failed during sending. Sending InternalServerError close frame."); + LoggerMessage.Define(LogLevel.Debug, new EventId(4, nameof(FailedSending)), "{time}: Connection Id {connectionId}: Application failed during sending. Sending InternalServerError close frame."); private static readonly Action _finishedSending = - LoggerMessage.Define(LogLevel.Debug, 5, "{time}: Connection Id {connectionId}: Application finished sending. Sending close frame."); + LoggerMessage.Define(LogLevel.Debug, new EventId(5, nameof(FinishedSending)), "{time}: Connection Id {connectionId}: Application finished sending. Sending close frame."); private static readonly Action _waitingForClose = - LoggerMessage.Define(LogLevel.Debug, 6, "{time}: Connection Id {connectionId}: Waiting for the client to close the socket."); + LoggerMessage.Define(LogLevel.Debug, new EventId(6, nameof(WaitingForClose)), "{time}: Connection Id {connectionId}: Waiting for the client to close the socket."); private static readonly Action _closeTimedOut = - LoggerMessage.Define(LogLevel.Debug, 7, "{time}: Connection Id {connectionId}: Timed out waiting for client to send the close frame, aborting the connection."); + LoggerMessage.Define(LogLevel.Debug, new EventId(7, nameof(CloseTimedOut)), "{time}: Connection Id {connectionId}: Timed out waiting for client to send the close frame, aborting the connection."); private static readonly Action _messageReceived = - LoggerMessage.Define(LogLevel.Debug, 8, "{time}: Connection Id {connectionId}: Message received. Type: {messageType}, size: {size}, EndOfMessage: {endOfMessage}."); + LoggerMessage.Define(LogLevel.Debug, new EventId(8, nameof(MessageReceived)), "{time}: Connection Id {connectionId}: Message received. Type: {messageType}, size: {size}, EndOfMessage: {endOfMessage}."); private static readonly Action _messageToApplication = - LoggerMessage.Define(LogLevel.Debug, 9, "{time}: Connection Id {connectionId}: Passing message to application. Payload size: {size}."); + LoggerMessage.Define(LogLevel.Debug, new EventId(9, nameof(MessageToApplication)), "{time}: Connection Id {connectionId}: Passing message to application. Payload size: {size}."); private static readonly Action _sendPayload = - LoggerMessage.Define(LogLevel.Debug, 10, "{time}: Connection Id {connectionId}: Sending payload: {size} bytes."); + LoggerMessage.Define(LogLevel.Debug, new EventId(10, nameof(SendPayload)), "{time}: Connection Id {connectionId}: Sending payload: {size} bytes."); private static readonly Action _errorWritingFrame = - LoggerMessage.Define(LogLevel.Error, 11, "{time}: Connection Id {connectionId}: Error writing frame."); + LoggerMessage.Define(LogLevel.Error, new EventId(11, nameof(ErrorWritingFrame)), "{time}: Connection Id {connectionId}: Error writing frame."); private static readonly Action _sendFailed = - LoggerMessage.Define(LogLevel.Trace, 12, "{time}: Connection Id {connectionId}: Socket failed to send."); + LoggerMessage.Define(LogLevel.Trace, new EventId(12, nameof(SendFailed)), "{time}: Connection Id {connectionId}: Socket failed to send."); // Category: ServerSentEventsTransport private static readonly Action _sseWritingMessage = - LoggerMessage.Define(LogLevel.Debug, 0, "{time}: Connection Id {connectionId}: Writing a {count} byte message."); + LoggerMessage.Define(LogLevel.Debug, new EventId(0, nameof(SSEWritingMessage)), "{time}: Connection Id {connectionId}: Writing a {count} byte message."); public static void LongPolling204(this ILogger logger, string connectionId, string requestId) { diff --git a/src/Microsoft.AspNetCore.Sockets/Internal/SocketLoggerExtensions.cs b/src/Microsoft.AspNetCore.Sockets/Internal/SocketLoggerExtensions.cs index 8854633644..82af61fbeb 100644 --- a/src/Microsoft.AspNetCore.Sockets/Internal/SocketLoggerExtensions.cs +++ b/src/Microsoft.AspNetCore.Sockets/Internal/SocketLoggerExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; @@ -10,16 +10,16 @@ namespace Microsoft.AspNetCore.Sockets.Internal { // Category: ConnectionManager private static readonly Action _createdNewConnection = - LoggerMessage.Define(LogLevel.Debug, 0, "{time}: ConnectionId {connectionId}: New connection created."); + LoggerMessage.Define(LogLevel.Debug, new EventId(0, nameof(CreatedNewConnection)), "{time}: ConnectionId {connectionId}: New connection created."); private static readonly Action _removedConnection = - LoggerMessage.Define(LogLevel.Debug, 1, "{time}: ConnectionId {connectionId}: Removing connection from the list of connections."); + 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, 2, "{time}: ConnectionId {connectionId}: Failed disposing connection."); + LoggerMessage.Define(LogLevel.Error, new EventId(2, nameof(FailedDispose)), "{time}: ConnectionId {connectionId}: Failed disposing connection."); private static readonly Action _connectionReset = - LoggerMessage.Define(LogLevel.Trace, 3, "{time}: ConnectionId {connectionId}: Connection was reset."); + LoggerMessage.Define(LogLevel.Trace, new EventId(3, nameof(ConnectionReset)), "{time}: ConnectionId {connectionId}: Connection was reset."); public static void CreatedNewConnection(this ILogger logger, string connectionId) {