diff --git a/client-ts/signalr/src/HttpConnection.ts b/client-ts/signalr/src/HttpConnection.ts index 8a2055dca1..0dd0fd5e54 100644 --- a/client-ts/signalr/src/HttpConnection.ts +++ b/client-ts/signalr/src/HttpConnection.ts @@ -174,6 +174,12 @@ export class HttpConnection implements IConnection { this.transport = null; } + if (error) { + this.logger.log(LogLevel.Error, `Connection disconnected with error '${error}'.`); + } else { + this.logger.log(LogLevel.Information, "Connection disconnected."); + } + this.connectionState = ConnectionState.Disconnected; if (raiseClosed && this.onclose) { diff --git a/client-ts/signalr/src/HubConnection.ts b/client-ts/signalr/src/HubConnection.ts index f61307c601..b4a252882e 100644 --- a/client-ts/signalr/src/HubConnection.ts +++ b/client-ts/signalr/src/HubConnection.ts @@ -132,6 +132,8 @@ export class HubConnection { this.callbacks.clear(); this.closedCallbacks.forEach(c => c.apply(this, [error])); + + this.cleanupTimeout(); } async start(): Promise { @@ -158,9 +160,7 @@ export class HubConnection { } stop(): Promise { - if (this.timeoutHandle) { - clearTimeout(this.timeoutHandle); - } + this.cleanupTimeout(); return this.connection.stop(); } @@ -285,6 +285,12 @@ export class HubConnection { } } + private cleanupTimeout(): void { + if (this.timeoutHandle) { + clearTimeout(this.timeoutHandle); + } + } + private createInvocation(methodName: string, args: any[], nonblocking: boolean): InvocationMessage { if (nonblocking) { return { diff --git a/samples/SocketsSample/wwwroot/hubs.html b/samples/SocketsSample/wwwroot/hubs.html index eb9d2900f9..5bd4b73805 100644 --- a/samples/SocketsSample/wwwroot/hubs.html +++ b/samples/SocketsSample/wwwroot/hubs.html @@ -104,7 +104,7 @@ connectButton.disabled = true; disconnectButton.disabled = false; console.log('http://' + document.location.host + '/' + hubRoute); - connection = new signalR.HubConnection(hubRoute, { transport: transportType, logging: logger }); + connection = new signalR.HubConnection(hubRoute, { transport: transportType, logger: logger }); connection.on('Send', function (msg) { addLine('message-list', msg); }); diff --git a/samples/SocketsSample/wwwroot/sockets.html b/samples/SocketsSample/wwwroot/sockets.html index 554c90eda5..5084b71ea2 100644 --- a/samples/SocketsSample/wwwroot/sockets.html +++ b/samples/SocketsSample/wwwroot/sockets.html @@ -1,4 +1,4 @@ - + @@ -24,7 +24,7 @@ document.getElementById('transportName').innerHTML = signalR.TransportType[transportType]; let url = 'http://' + document.location.host + '/chat'; - let connection = new signalR.HttpConnection(url, { transport: transportType, logging: new signalR.ConsoleLogger(signalR.LogLevel.Trace) }); + let connection = new signalR.HttpConnection(url, { transport: transportType, logger: new signalR.ConsoleLogger(signalR.LogLevel.Trace) }); connection.onreceive = function (data) { let child = document.createElement('li'); diff --git a/samples/SocketsSample/wwwroot/streaming.html b/samples/SocketsSample/wwwroot/streaming.html index 3e0c25aefc..41057281da 100644 --- a/samples/SocketsSample/wwwroot/streaming.html +++ b/samples/SocketsSample/wwwroot/streaming.html @@ -1,4 +1,4 @@ - + @@ -54,7 +54,7 @@ }); click('connectButton', function () { - connection = new signalR.HubConnection('/streaming', { transport: transportType, logging: logger }); + connection = new signalR.HubConnection('/streaming', { transport: transportType, logger: logger }); connection.onclose(function () { channelButton.disabled = true; diff --git a/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs b/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs index 0fa46194fc..439311626f 100644 --- a/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs +++ b/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs @@ -313,7 +313,7 @@ namespace Microsoft.AspNetCore.SignalR.Client try { - _logger.PreparingNonBlockingInvocation(invocationMessage.InvocationId, methodName, args.Length); + _logger.PreparingNonBlockingInvocation(methodName, args.Length); var payload = _protocolReaderWriter.WriteMessage(invocationMessage); _logger.SendInvocation(invocationMessage.InvocationId); diff --git a/src/Microsoft.AspNetCore.SignalR.Client.Core/Internal/SignalRClientLoggerExtensions.cs b/src/Microsoft.AspNetCore.SignalR.Client.Core/Internal/SignalRClientLoggerExtensions.cs index cc959acf6b..b3a41cc7e8 100644 --- a/src/Microsoft.AspNetCore.SignalR.Client.Core/Internal/SignalRClientLoggerExtensions.cs +++ b/src/Microsoft.AspNetCore.SignalR.Client.Core/Internal/SignalRClientLoggerExtensions.cs @@ -10,8 +10,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.Internal internal static class SignalRClientLoggerExtensions { // Category: HubConnection - private static readonly Action _preparingNonBlockingInvocation = - LoggerMessage.Define(LogLevel.Trace, new EventId(1, nameof(PreparingNonBlockingInvocation)), "Preparing non-blocking invocation '{invocationId}' of '{target}', with {argumentCount} argument(s)."); + private static readonly Action _preparingNonBlockingInvocation = + LoggerMessage.Define(LogLevel.Trace, new EventId(1, nameof(PreparingNonBlockingInvocation)), "Preparing non-blocking invocation of '{target}', with {argumentCount} argument(s)."); private static readonly Action _preparingBlockingInvocation = LoggerMessage.Define(LogLevel.Trace, new EventId(2, nameof(PreparingBlockingInvocation)), "Preparing blocking invocation '{invocationId}' of '{target}', with return type '{returnType}' and {argumentCount} argument(s)."); @@ -118,9 +118,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.Internal private static readonly Action _errorInvokingClientSideMethod = LoggerMessage.Define(LogLevel.Error, new EventId(6, nameof(ErrorInvokingClientSideMethod)), "Invoking client side method '{methodName}' failed."); - public static void PreparingNonBlockingInvocation(this ILogger logger, string invocationId, string target, int count) + public static void PreparingNonBlockingInvocation(this ILogger logger, string target, int count) { - _preparingNonBlockingInvocation(logger, invocationId, target, count, null); + _preparingNonBlockingInvocation(logger, target, count, null); } public static void PreparingBlockingInvocation(this ILogger logger, string invocationId, string target, string returnType, int count) diff --git a/src/Microsoft.AspNetCore.SignalR.Core/HubEndPoint.cs b/src/Microsoft.AspNetCore.SignalR.Core/HubEndPoint.cs index 5f1b889f72..61db155e30 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/HubEndPoint.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/HubEndPoint.cs @@ -306,13 +306,13 @@ namespace Microsoft.AspNetCore.SignalR if (isStreamedInvocation) { var enumerator = GetStreamingEnumerator(connection, hubMethodInvocationMessage.InvocationId, methodExecutor, result, methodExecutor.MethodReturnType); - _logger.StreamingResult(hubMethodInvocationMessage.InvocationId, methodExecutor.MethodReturnType.FullName); + _logger.StreamingResult(hubMethodInvocationMessage.InvocationId, methodExecutor); await StreamResultsAsync(hubMethodInvocationMessage.InvocationId, connection, enumerator); } // Non-empty/null InvocationId ==> Blocking invocation that needs a response else if (!string.IsNullOrEmpty(hubMethodInvocationMessage.InvocationId)) { - _logger.SendingResult(hubMethodInvocationMessage.InvocationId, methodExecutor.MethodReturnType.FullName); + _logger.SendingResult(hubMethodInvocationMessage.InvocationId, methodExecutor); await SendMessageAsync(connection, CompletionMessage.WithResult(hubMethodInvocationMessage.InvocationId, result)); } } @@ -506,6 +506,7 @@ namespace Microsoft.AspNetCore.SignalR { var hubType = typeof(THub); var hubTypeInfo = hubType.GetTypeInfo(); + var hubName = hubType.Name; foreach (var methodInfo in HubReflectionHelper.GetHubMethods(hubType)) { @@ -522,7 +523,7 @@ namespace Microsoft.AspNetCore.SignalR var authorizeAttributes = methodInfo.GetCustomAttributes(inherit: true); _methods[methodName] = new HubMethodDescriptor(executor, authorizeAttributes); - _logger.HubMethodBound(methodName); + _logger.HubMethodBound(hubName, methodName); } } diff --git a/src/Microsoft.AspNetCore.SignalR.Core/Internal/SignalRCoreLoggerExtensions.cs b/src/Microsoft.AspNetCore.SignalR.Core/Internal/SignalRCoreLoggerExtensions.cs index bd73aba55a..3ef594610a 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/Internal/SignalRCoreLoggerExtensions.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/Internal/SignalRCoreLoggerExtensions.cs @@ -3,6 +3,7 @@ using System; using Microsoft.AspNetCore.SignalR.Internal.Protocol; +using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.SignalR.Internal @@ -32,16 +33,16 @@ namespace Microsoft.AspNetCore.SignalR.Internal LoggerMessage.Define(LogLevel.Debug, new EventId(7, nameof(HubMethodNotAuthorized)), "Failed to invoke '{hubMethod}' because user is unauthorized."); private static readonly Action _streamingResult = - LoggerMessage.Define(LogLevel.Trace, new EventId(8, nameof(StreamingResult)), "{invocationId}: Streaming result of type '{resultType}'."); + LoggerMessage.Define(LogLevel.Trace, new EventId(8, nameof(StreamingResult)), "InvocationId {invocationId}: Streaming result of type '{resultType}'."); private static readonly Action _sendingResult = - LoggerMessage.Define(LogLevel.Trace, new EventId(9, nameof(SendingResult)), "{invocationId}: Sending result of type '{resultType}'."); + LoggerMessage.Define(LogLevel.Trace, new EventId(9, nameof(SendingResult)), "InvocationId {invocationId}: Sending result of type '{resultType}'."); private static readonly Action _failedInvokingHubMethod = LoggerMessage.Define(LogLevel.Error, new EventId(10, nameof(FailedInvokingHubMethod)), "Failed to invoke hub method '{hubMethod}'."); - private static readonly Action _hubMethodBound = - LoggerMessage.Define(LogLevel.Trace, new EventId(11, nameof(HubMethodBound)), "Hub method '{hubMethod}' is bound."); + private static readonly Action _hubMethodBound = + LoggerMessage.Define(LogLevel.Trace, new EventId(11, nameof(HubMethodBound)), "'{hubName}' hub method '{hubMethod}' is bound."); private static readonly Action _cancelStream = LoggerMessage.Define(LogLevel.Debug, new EventId(12, nameof(CancelStream)), "Canceling stream for invocation {invocationId}."); @@ -129,14 +130,16 @@ namespace Microsoft.AspNetCore.SignalR.Internal _hubMethodNotAuthorized(logger, hubMethod, null); } - public static void StreamingResult(this ILogger logger, string invocationId, string resultType) + public static void StreamingResult(this ILogger logger, string invocationId, ObjectMethodExecutor objectMethodExecutor) { - _streamingResult(logger, invocationId, resultType, null); + var resultType = objectMethodExecutor.AsyncResultType == null ? objectMethodExecutor.MethodReturnType : objectMethodExecutor.AsyncResultType; + _streamingResult(logger, invocationId, resultType.FullName, null); } - public static void SendingResult(this ILogger logger, string invocationId, string resultType) + public static void SendingResult(this ILogger logger, string invocationId, ObjectMethodExecutor objectMethodExecutor) { - _sendingResult(logger, invocationId, resultType, null); + var resultType = objectMethodExecutor.AsyncResultType == null ? objectMethodExecutor.MethodReturnType : objectMethodExecutor.AsyncResultType; + _sendingResult(logger, invocationId, resultType.FullName, null); } public static void FailedInvokingHubMethod(this ILogger logger, string hubMethod, Exception exception) @@ -144,9 +147,9 @@ namespace Microsoft.AspNetCore.SignalR.Internal _failedInvokingHubMethod(logger, hubMethod, exception); } - public static void HubMethodBound(this ILogger logger, string hubMethod) + public static void HubMethodBound(this ILogger logger, string hubName, string hubMethod) { - _hubMethodBound(logger, hubMethod, null); + _hubMethodBound(logger, hubName, hubMethod, null); } public static void CancelStream(this ILogger logger, string invocationId) diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.cs index 4e0c369795..68d6ad8b6f 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.cs @@ -47,6 +47,8 @@ namespace Microsoft.AspNetCore.Sockets.Client private ChannelWriter Output => _transportChannel.Output; private readonly List _callbacks = new List(); private readonly TransportType _requestedTransportType = TransportType.All; + private readonly ConnectionLogScope _logScope; + private readonly IDisposable _scopeDisposable; public Uri Url { get; } @@ -89,6 +91,8 @@ namespace Microsoft.AspNetCore.Sockets.Client } _transportFactory = new DefaultTransportFactory(transportType, _loggerFactory, _httpClient, httpOptions); + _logScope = new ConnectionLogScope(); + _scopeDisposable = _logger.BeginScope(_logScope); } public HttpConnection(Uri url, ITransportFactory transportFactory, ILoggerFactory loggerFactory, HttpOptions httpOptions) @@ -100,6 +104,8 @@ namespace Microsoft.AspNetCore.Sockets.Client _httpClient = _httpOptions?.HttpMessageHandler == null ? new HttpClient() : new HttpClient(_httpOptions?.HttpMessageHandler); _httpClient.Timeout = HttpClientTimeout; _transportFactory = transportFactory ?? throw new ArgumentNullException(nameof(transportFactory)); + _logScope = new ConnectionLogScope(); + _scopeDisposable = _logger.BeginScope(_logScope); } public async Task StartAsync() => await StartAsyncCore().ForceAsync(); @@ -151,11 +157,12 @@ namespace Microsoft.AspNetCore.Sockets.Client { var negotiationResponse = await Negotiate(Url, _httpClient, _logger); _connectionId = negotiationResponse.ConnectionId; + _logScope.ConnectionId = _connectionId; // Connection is being disposed while start was in progress if (_connectionState == ConnectionState.Disposed) { - _logger.HttpConnectionClosed(_connectionId); + _logger.HttpConnectionClosed(); return; } @@ -163,7 +170,7 @@ namespace Microsoft.AspNetCore.Sockets.Client connectUrl = CreateConnectUrl(Url, negotiationResponse); } - _logger.StartingTransport(_connectionId, _transport.GetType().Name, connectUrl); + _logger.StartingTransport(_transport, connectUrl); await StartTransport(connectUrl); } catch @@ -193,16 +200,17 @@ namespace Microsoft.AspNetCore.Sockets.Client // to make sure that the message removed from the channel is processed before we drain the queue. // There is a short window between we start the channel and assign the _receiveLoopTask a value. // To make sure that _receiveLoopTask can be awaited (i.e. is not null) we need to await _startTask. - _logger.ProcessRemainingMessages(_connectionId); + _logger.ProcessRemainingMessages(); await _startTcs.Task; await _receiveLoopTask; - _logger.DrainEvents(_connectionId); + _logger.DrainEvents(); await Task.WhenAny(_eventQueue.Drain().NoThrow(), Task.Delay(_eventQueueDrainTimeout)); - _logger.CompleteClosed(_connectionId); + _logger.CompleteClosed(); + _logScope.ConnectionId = null; // At this point the connection can be either in the Connected or Disposed state. The state should be changed // to the Disconnected state only if it was in the Connected state. @@ -325,7 +333,7 @@ namespace Microsoft.AspNetCore.Sockets.Client // Start the transport, giving it one end of the pipeline try { - await _transport.StartAsync(connectUrl, applicationSide, GetTransferMode(), _connectionId, this); + await _transport.StartAsync(connectUrl, applicationSide, GetTransferMode(), this); // actual transfer mode can differ from the one that was requested so set it on the feature if (!_transport.Mode.HasValue) @@ -337,7 +345,7 @@ namespace Microsoft.AspNetCore.Sockets.Client } catch (Exception ex) { - _logger.ErrorStartingTransport(_connectionId, _transport.GetType().Name, ex); + _logger.ErrorStartingTransport(_transport, ex); throw; } } @@ -369,13 +377,13 @@ namespace Microsoft.AspNetCore.Sockets.Client { try { - _logger.HttpReceiveStarted(_connectionId); + _logger.HttpReceiveStarted(); while (await Input.WaitToReadAsync()) { if (_connectionState != ConnectionState.Connected) { - _logger.SkipRaisingReceiveEvent(_connectionId); + _logger.SkipRaisingReceiveEvent(); // drain Input.TryRead(out _); continue; @@ -383,10 +391,10 @@ namespace Microsoft.AspNetCore.Sockets.Client if (Input.TryRead(out var buffer)) { - _logger.ScheduleReceiveEvent(_connectionId); + _logger.ScheduleReceiveEvent(); _ = _eventQueue.Enqueue(async () => { - _logger.RaiseReceiveEvent(_connectionId); + _logger.RaiseReceiveEvent(); // Copying the callbacks to avoid concurrency issues ReceiveCallback[] callbackCopies; @@ -404,14 +412,14 @@ namespace Microsoft.AspNetCore.Sockets.Client } catch (Exception ex) { - _logger.ExceptionThrownFromCallback(_connectionId, nameof(OnReceived), ex); + _logger.ExceptionThrownFromCallback(nameof(OnReceived), ex); } } }); } else { - _logger.FailedReadingMessage(_connectionId); + _logger.FailedReadingMessage(); } } @@ -420,10 +428,10 @@ namespace Microsoft.AspNetCore.Sockets.Client catch (Exception ex) { Output.TryComplete(ex); - _logger.ErrorReceiving(_connectionId, ex); + _logger.ErrorReceiving(ex); } - _logger.EndReceive(_connectionId); + _logger.EndReceive(); } public async Task SendAsync(byte[] data, CancellationToken cancellationToken = default) => @@ -449,7 +457,7 @@ namespace Microsoft.AspNetCore.Sockets.Client var sendTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var message = new SendMessage(data, sendTcs); - _logger.SendingMessage(_connectionId); + _logger.SendingMessage(); while (await Output.WaitToWriteAsync(cancellationToken)) { @@ -483,7 +491,7 @@ namespace Microsoft.AspNetCore.Sockets.Client { if (!(_connectionState == ConnectionState.Connecting || _connectionState == ConnectionState.Connected)) { - _logger.SkippingStop(_connectionId); + _logger.SkippingStop(); return; } } @@ -496,7 +504,7 @@ namespace Microsoft.AspNetCore.Sockets.Client // See comment at AbortAsync for more discussion on the thread-safety of this. _abortException = exception; - _logger.StoppingClient(_connectionId); + _logger.StoppingClient(); try { @@ -538,15 +546,16 @@ namespace Microsoft.AspNetCore.Sockets.Client if (ChangeState(to: ConnectionState.Disposed) == ConnectionState.Disposed) { - _logger.SkippingDispose(_connectionId); + _logger.SkippingDispose(); // the connection was already disposed return; } - _logger.DisposingClient(_connectionId); + _logger.DisposingClient(); _httpClient?.Dispose(); + _scopeDisposable.Dispose(); } public IDisposable OnReceived(Func callback, object state) @@ -605,7 +614,7 @@ namespace Microsoft.AspNetCore.Sockets.Client _connectionState = to; } - _logger.ConnectionStateChanged(_connectionId, state, to); + _logger.ConnectionStateChanged(state, to); return state; } } @@ -616,7 +625,7 @@ namespace Microsoft.AspNetCore.Sockets.Client { var state = _connectionState; _connectionState = to; - _logger.ConnectionStateChanged(_connectionId, state, to); + _logger.ConnectionStateChanged(state, to); return state; } } diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/ITransport.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/ITransport.cs index 620e0e1a1d..0587ef0684 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/ITransport.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/ITransport.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Sockets.Client { public interface ITransport { - Task StartAsync(Uri url, Channel application, TransferMode requestedTransferMode, string connectionId, IConnection connection); + Task StartAsync(Uri url, Channel application, TransferMode requestedTransferMode, IConnection connection); Task StopAsync(); TransferMode? Mode { get; } } diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/Internal/ConnectionLogScope.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/Internal/ConnectionLogScope.cs new file mode 100644 index 0000000000..cc040296b8 --- /dev/null +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/Internal/ConnectionLogScope.cs @@ -0,0 +1,73 @@ +// 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 System.Collections; +using System.Collections.Generic; +using System.Globalization; + +namespace Microsoft.AspNetCore.Sockets.Http.Internal +{ + public class ConnectionLogScope : IReadOnlyList> + { + private string _cachedToString; + private string _connectionId; + + public string ConnectionId + { + get + { + return _connectionId; + } + set + { + _cachedToString = null; + _connectionId = value; + } + } + + public KeyValuePair this[int index] + { + get + { + if (Count == 1 && index == 0) + { + return new KeyValuePair("ClientConnectionId", ConnectionId); + } + + throw new ArgumentOutOfRangeException(nameof(index)); + } + } + + public int Count => string.IsNullOrEmpty(ConnectionId) ? 0 : 1; + + public IEnumerator> GetEnumerator() + { + for (var i = 0; i < Count; ++i) + { + yield return this[i]; + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public override string ToString() + { + if (_cachedToString == null) + { + if (!string.IsNullOrEmpty(ConnectionId)) + { + _cachedToString = string.Format( + CultureInfo.InvariantCulture, + "ClientConnectionId:{0}", + ConnectionId); + } + } + + return _cachedToString; + } + } +} diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/Internal/SocketClientLoggerExtensions.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/Internal/SocketClientLoggerExtensions.cs index 81479979f3..870175a819 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/Internal/SocketClientLoggerExtensions.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/Internal/SocketClientLoggerExtensions.cs @@ -10,573 +10,429 @@ namespace Microsoft.AspNetCore.Sockets.Client.Internal internal static class SocketClientLoggerExtensions { // Category: Shared with LongPollingTransport, WebSocketsTransport and ServerSentEventsTransport - private static readonly Action _startTransport = - LoggerMessage.Define(LogLevel.Information, new EventId(1, nameof(StartTransport)), "{time}: Connection Id {connectionId}: Starting transport. Transfer mode: {transferMode}."); + private static readonly Action _startTransport = + LoggerMessage.Define(LogLevel.Information, new EventId(1, nameof(StartTransport)), "Starting transport. Transfer mode: {transferMode}."); - private static readonly Action _transportStopped = - LoggerMessage.Define(LogLevel.Debug, new EventId(2, nameof(TransportStopped)), "{time}: Connection Id {connectionId}: Transport stopped."); + private static readonly Action _transportStopped = + LoggerMessage.Define(LogLevel.Debug, new EventId(2, nameof(TransportStopped)), "Transport stopped."); - private static readonly Action _startReceive = - LoggerMessage.Define(LogLevel.Debug, new EventId(3, nameof(StartReceive)), "{time}: Connection Id {connectionId}: Starting receive loop."); + private static readonly Action _startReceive = + LoggerMessage.Define(LogLevel.Debug, new EventId(3, nameof(StartReceive)), "Starting receive loop."); - private static readonly Action _receiveStopped = - LoggerMessage.Define(LogLevel.Debug, new EventId(4, nameof(ReceiveStopped)), "{time}: Connection Id {connectionId}: Receive loop stopped."); + private static readonly Action _receiveStopped = + LoggerMessage.Define(LogLevel.Debug, new EventId(4, nameof(ReceiveStopped)), "Receive loop stopped."); - private static readonly Action _receiveCanceled = - LoggerMessage.Define(LogLevel.Debug, new EventId(5, nameof(ReceiveCanceled)), "{time}: Connection Id {connectionId}: Receive loop canceled."); + private static readonly Action _receiveCanceled = + LoggerMessage.Define(LogLevel.Debug, new EventId(5, nameof(ReceiveCanceled)), "Receive loop canceled."); - private static readonly Action _transportStopping = - LoggerMessage.Define(LogLevel.Information, new EventId(6, nameof(TransportStopping)), "{time}: Connection Id {connectionId}: Transport is stopping."); + private static readonly Action _transportStopping = + LoggerMessage.Define(LogLevel.Information, new EventId(6, nameof(TransportStopping)), "Transport is stopping."); - private static readonly Action _sendStarted = - LoggerMessage.Define(LogLevel.Debug, new EventId(7, nameof(SendStarted)), "{time}: Connection Id {connectionId}: Starting the send loop."); + private static readonly Action _sendStarted = + LoggerMessage.Define(LogLevel.Debug, new EventId(7, nameof(SendStarted)), "Starting the send loop."); - private static readonly Action _sendStopped = - LoggerMessage.Define(LogLevel.Debug, new EventId(8, nameof(SendStopped)), "{time}: Connection Id {connectionId}: Send loop stopped."); + private static readonly Action _sendStopped = + LoggerMessage.Define(LogLevel.Debug, new EventId(8, nameof(SendStopped)), "Send loop stopped."); - private static readonly Action _sendCanceled = - LoggerMessage.Define(LogLevel.Debug, new EventId(9, nameof(SendCanceled)), "{time}: Connection Id {connectionId}: Send loop canceled."); + private static readonly Action _sendCanceled = + LoggerMessage.Define(LogLevel.Debug, new EventId(9, nameof(SendCanceled)), "Send loop canceled."); // Category: WebSocketsTransport - private static readonly Action _webSocketClosed = - LoggerMessage.Define(LogLevel.Information, new EventId(10, nameof(WebSocketClosed)), "{time}: Connection Id {connectionId}: Websocket closed by the server. Close status {closeStatus}."); + private static readonly Action _webSocketClosed = + LoggerMessage.Define(LogLevel.Information, new EventId(10, nameof(WebSocketClosed)), "Websocket closed by the server. Close status {closeStatus}."); - private static readonly Action _messageReceived = - LoggerMessage.Define(LogLevel.Debug, new EventId(11, nameof(MessageReceived)), "{time}: Connection Id {connectionId}: Message received. Type: {messageType}, size: {count}, EndOfMessage: {endOfMessage}."); + private static readonly Action _messageReceived = + LoggerMessage.Define(LogLevel.Debug, new EventId(11, nameof(MessageReceived)), "Message received. Type: {messageType}, size: {count}, EndOfMessage: {endOfMessage}."); - private static readonly Action _messageToApp = - LoggerMessage.Define(LogLevel.Debug, new EventId(12, nameof(MessageToApp)), "{time}: Connection Id {connectionId}: Passing message to application. Payload size: {count}."); + private static readonly Action _messageToApp = + LoggerMessage.Define(LogLevel.Debug, new EventId(12, nameof(MessageToApp)), "Passing message to application. Payload size: {count}."); - private static readonly Action _receivedFromApp = - LoggerMessage.Define(LogLevel.Debug, new EventId(13, nameof(ReceivedFromApp)), "{time}: Connection Id {connectionId}: Received message from application. Payload size: {count}."); + private static readonly Action _receivedFromApp = + LoggerMessage.Define(LogLevel.Debug, new EventId(13, nameof(ReceivedFromApp)), "Received message from application. Payload size: {count}."); - private static readonly Action _sendMessageCanceled = - LoggerMessage.Define(LogLevel.Information, new EventId(14, nameof(SendMessageCanceled)), "{time}: Connection Id {connectionId}: Sending a message canceled."); + private static readonly Action _sendMessageCanceled = + LoggerMessage.Define(LogLevel.Information, new EventId(14, nameof(SendMessageCanceled)), "Sending a message canceled."); - private static readonly Action _errorSendingMessage = - LoggerMessage.Define(LogLevel.Error, new EventId(15, nameof(ErrorSendingMessage)), "{time}: Connection Id {connectionId}: Error while sending a message."); + private static readonly Action _errorSendingMessage = + LoggerMessage.Define(LogLevel.Error, new EventId(15, nameof(ErrorSendingMessage)), "Error while sending a message."); - private static readonly Action _closingWebSocket = - LoggerMessage.Define(LogLevel.Information, new EventId(16, nameof(ClosingWebSocket)), "{time}: Connection Id {connectionId}: Closing WebSocket."); + private static readonly Action _closingWebSocket = + LoggerMessage.Define(LogLevel.Information, new EventId(16, nameof(ClosingWebSocket)), "Closing WebSocket."); - private static readonly Action _closingWebSocketFailed = - LoggerMessage.Define(LogLevel.Information, new EventId(17, nameof(ClosingWebSocketFailed)), "{time}: Connection Id {connectionId}: Closing webSocket failed."); + private static readonly Action _closingWebSocketFailed = + LoggerMessage.Define(LogLevel.Information, new EventId(17, nameof(ClosingWebSocketFailed)), "Closing webSocket failed."); - private static readonly Action _cancelMessage = - LoggerMessage.Define(LogLevel.Debug, new EventId(18, nameof(CancelMessage)), "{time}: Connection Id {connectionId}: Canceled passing message to application."); + private static readonly Action _cancelMessage = + LoggerMessage.Define(LogLevel.Debug, new EventId(18, nameof(CancelMessage)), "Canceled passing message to application."); // Category: ServerSentEventsTransport and LongPollingTransport - private static readonly Action _sendingMessages = - LoggerMessage.Define(LogLevel.Debug, new EventId(10, nameof(SendingMessages)), "{time}: Connection Id {connectionId}: Sending {count} message(s) to the server using url: {url}."); + private static readonly Action _sendingMessages = + LoggerMessage.Define(LogLevel.Debug, new EventId(10, nameof(SendingMessages)), "Sending {count} message(s) to the server using url: {url}."); - private static readonly Action _sentSuccessfully = - LoggerMessage.Define(LogLevel.Debug, new EventId(11, nameof(SentSuccessfully)), "{time}: Connection Id {connectionId}: Message(s) sent successfully."); + private static readonly Action _sentSuccessfully = + LoggerMessage.Define(LogLevel.Debug, new EventId(11, nameof(SentSuccessfully)), "Message(s) sent successfully."); - private static readonly Action _noMessages = - LoggerMessage.Define(LogLevel.Debug, new EventId(12, nameof(NoMessages)), "{time}: Connection Id {connectionId}: No messages in batch to send."); + private static readonly Action _noMessages = + LoggerMessage.Define(LogLevel.Debug, new EventId(12, nameof(NoMessages)), "No messages in batch to send."); - private static readonly Action _errorSending = - LoggerMessage.Define(LogLevel.Error, new EventId(13, nameof(ErrorSending)), "{time}: Connection Id {connectionId}: Error while sending to '{url}'."); + private static readonly Action _errorSending = + LoggerMessage.Define(LogLevel.Error, new EventId(13, nameof(ErrorSending)), "Error while sending to '{url}'."); // Category: ServerSentEventsTransport - private static readonly Action _eventStreamEnded = - LoggerMessage.Define(LogLevel.Debug, new EventId(14, nameof(EventStreamEnded)), "{time}: Connection Id {connectionId}: Server-Sent Event Stream ended."); + private static readonly Action _eventStreamEnded = + LoggerMessage.Define(LogLevel.Debug, new EventId(14, nameof(EventStreamEnded)), "Server-Sent Event Stream ended."); // Category: LongPollingTransport - private static readonly Action _closingConnection = - LoggerMessage.Define(LogLevel.Debug, new EventId(14, nameof(ClosingConnection)), "{time}: Connection Id {connectionId}: The server is closing the connection."); + private static readonly Action _closingConnection = + LoggerMessage.Define(LogLevel.Debug, new EventId(14, nameof(ClosingConnection)), "The server is closing the connection."); - private static readonly Action _receivedMessages = - LoggerMessage.Define(LogLevel.Debug, new EventId(15, nameof(ReceivedMessages)), "{time}: Connection Id {connectionId}: Received messages from the server."); + private static readonly Action _receivedMessages = + LoggerMessage.Define(LogLevel.Debug, new EventId(15, nameof(ReceivedMessages)), "Received messages from the server."); - private static readonly Action _errorPolling = - LoggerMessage.Define(LogLevel.Error, new EventId(16, nameof(ErrorPolling)), "{time}: Connection Id {connectionId}: Error while polling '{pollUrl}'."); + private static readonly Action _errorPolling = + LoggerMessage.Define(LogLevel.Error, new EventId(16, nameof(ErrorPolling)), "Error while polling '{pollUrl}'."); // Category: HttpConnection - private static readonly Action _httpConnectionStarting = - LoggerMessage.Define(LogLevel.Debug, new EventId(1, nameof(HttpConnectionStarting)), "{time}: Starting connection."); + private static readonly Action _httpConnectionStarting = + LoggerMessage.Define(LogLevel.Debug, new EventId(1, nameof(HttpConnectionStarting)), "Starting connection."); - private static readonly Action _httpConnectionClosed = - LoggerMessage.Define(LogLevel.Debug, new EventId(2, nameof(HttpConnectionClosed)), "{time}: Connection Id {connectionId}: Connection was closed from a different thread."); + private static readonly Action _httpConnectionClosed = + LoggerMessage.Define(LogLevel.Debug, new EventId(2, nameof(HttpConnectionClosed)), "Connection was closed from a different thread."); - private static readonly Action _startingTransport = - LoggerMessage.Define(LogLevel.Debug, new EventId(3, nameof(StartingTransport)), "{time}: Connection Id {connectionId}: Starting transport '{transport}' with Url: {url}."); + private static readonly Action _startingTransport = + LoggerMessage.Define(LogLevel.Debug, new EventId(3, nameof(StartingTransport)), "Starting transport '{transport}' with Url: {url}."); - private static readonly Action _raiseConnected = - LoggerMessage.Define(LogLevel.Debug, new EventId(4, nameof(RaiseConnected)), "{time}: Connection Id {connectionId}: Raising Connected event."); + private static readonly Action _raiseConnected = + LoggerMessage.Define(LogLevel.Debug, new EventId(4, nameof(RaiseConnected)), "Raising Connected event."); - private static readonly Action _processRemainingMessages = - LoggerMessage.Define(LogLevel.Debug, new EventId(5, nameof(ProcessRemainingMessages)), "{time}: Connection Id {connectionId}: Ensuring all outstanding messages are processed."); + private static readonly Action _processRemainingMessages = + LoggerMessage.Define(LogLevel.Debug, new EventId(5, nameof(ProcessRemainingMessages)), "Ensuring all outstanding messages are processed."); - private static readonly Action _drainEvents = - LoggerMessage.Define(LogLevel.Debug, new EventId(6, nameof(DrainEvents)), "{time}: Connection Id {connectionId}: Draining event queue."); + private static readonly Action _drainEvents = + LoggerMessage.Define(LogLevel.Debug, new EventId(6, nameof(DrainEvents)), "Draining event queue."); - private static readonly Action _completeClosed = - LoggerMessage.Define(LogLevel.Debug, new EventId(7, nameof(CompleteClosed)), "{time}: Connection Id {connectionId}: Completing Closed task."); + private static readonly Action _completeClosed = + LoggerMessage.Define(LogLevel.Debug, new EventId(7, nameof(CompleteClosed)), "Completing Closed task."); - private static readonly Action _establishingConnection = - LoggerMessage.Define(LogLevel.Debug, new EventId(8, nameof(EstablishingConnection)), "{time}: Establishing Connection at: {url}."); + private static readonly Action _establishingConnection = + LoggerMessage.Define(LogLevel.Debug, new EventId(8, nameof(EstablishingConnection)), "Establishing Connection at: {url}."); - private static readonly Action _errorWithNegotiation = - LoggerMessage.Define(LogLevel.Error, new EventId(9, nameof(ErrorWithNegotiation)), "{time}: Failed to start connection. Error getting negotiation response from '{url}'."); + private static readonly Action _errorWithNegotiation = + LoggerMessage.Define(LogLevel.Error, new EventId(9, nameof(ErrorWithNegotiation)), "Failed to start connection. Error getting negotiation response from '{url}'."); - private static readonly Action _errorStartingTransport = - LoggerMessage.Define(LogLevel.Error, new EventId(10, nameof(ErrorStartingTransport)), "{time}: Connection Id {connectionId}: Failed to start connection. Error starting transport '{transport}'."); + private static readonly Action _errorStartingTransport = + LoggerMessage.Define(LogLevel.Error, new EventId(10, nameof(ErrorStartingTransport)), "Failed to start connection. Error starting transport '{transport}'."); - private static readonly Action _httpReceiveStarted = - LoggerMessage.Define(LogLevel.Trace, new EventId(11, nameof(HttpReceiveStarted)), "{time}: Connection Id {connectionId}: Beginning receive loop."); + private static readonly Action _httpReceiveStarted = + LoggerMessage.Define(LogLevel.Trace, new EventId(11, nameof(HttpReceiveStarted)), "Beginning receive loop."); - private static readonly Action _skipRaisingReceiveEvent = - LoggerMessage.Define(LogLevel.Debug, new EventId(12, nameof(SkipRaisingReceiveEvent)), "{time}: Connection Id {connectionId}: Message received but connection is not connected. Skipping raising Received event."); + private static readonly Action _skipRaisingReceiveEvent = + LoggerMessage.Define(LogLevel.Debug, new EventId(12, nameof(SkipRaisingReceiveEvent)), "Message received but connection is not connected. Skipping raising Received event."); - private static readonly Action _scheduleReceiveEvent = - LoggerMessage.Define(LogLevel.Debug, new EventId(13, nameof(ScheduleReceiveEvent)), "{time}: Connection Id {connectionId}: Scheduling raising Received event."); + private static readonly Action _scheduleReceiveEvent = + LoggerMessage.Define(LogLevel.Debug, new EventId(13, nameof(ScheduleReceiveEvent)), "Scheduling raising Received event."); - private static readonly Action _raiseReceiveEvent = - LoggerMessage.Define(LogLevel.Debug, new EventId(14, nameof(RaiseReceiveEvent)), "{time}: Connection Id {connectionId}: Raising Received event."); + private static readonly Action _raiseReceiveEvent = + LoggerMessage.Define(LogLevel.Debug, new EventId(14, nameof(RaiseReceiveEvent)), "Raising Received event."); - private static readonly Action _failedReadingMessage = - LoggerMessage.Define(LogLevel.Debug, new EventId(15, nameof(FailedReadingMessage)), "{time}: Connection Id {connectionId}: Could not read message."); + private static readonly Action _failedReadingMessage = + LoggerMessage.Define(LogLevel.Debug, new EventId(15, nameof(FailedReadingMessage)), "Could not read message."); - private static readonly Action _errorReceiving = - LoggerMessage.Define(LogLevel.Error, new EventId(16, nameof(ErrorReceiving)), "{time}: Connection Id {connectionId}: Error receiving message."); + private static readonly Action _errorReceiving = + LoggerMessage.Define(LogLevel.Error, new EventId(16, nameof(ErrorReceiving)), "Error receiving message."); - private static readonly Action _endReceive = - LoggerMessage.Define(LogLevel.Trace, new EventId(17, nameof(EndReceive)), "{time}: Connection Id {connectionId}: Ending receive loop."); + private static readonly Action _endReceive = + LoggerMessage.Define(LogLevel.Trace, new EventId(17, nameof(EndReceive)), "Ending receive loop."); - private static readonly Action _sendingMessage = - LoggerMessage.Define(LogLevel.Debug, new EventId(18, nameof(SendingMessage)), "{time}: Connection Id {connectionId}: Sending message."); + private static readonly Action _sendingMessage = + LoggerMessage.Define(LogLevel.Debug, new EventId(18, nameof(SendingMessage)), "Sending message."); - private static readonly Action _stoppingClient = - LoggerMessage.Define(LogLevel.Information, new EventId(19, nameof(StoppingClient)), "{time}: Connection Id {connectionId}: Stopping client."); + private static readonly Action _stoppingClient = + LoggerMessage.Define(LogLevel.Information, new EventId(19, nameof(StoppingClient)), "Stopping client."); - private static readonly Action _exceptionThrownFromCallback = - LoggerMessage.Define(LogLevel.Error, new EventId(20, nameof(ExceptionThrownFromCallback)), "{time}: Connection Id {connectionId}: An exception was thrown from the '{callback}' callback."); + private static readonly Action _exceptionThrownFromCallback = + LoggerMessage.Define(LogLevel.Error, new EventId(20, nameof(ExceptionThrownFromCallback)), "An exception was thrown from the '{callback}' callback."); - private static readonly Action _disposingClient = - LoggerMessage.Define(LogLevel.Information, new EventId(21, nameof(DisposingClient)), "{time}: Connection Id {connectionId}: Disposing client."); + private static readonly Action _disposingClient = + LoggerMessage.Define(LogLevel.Information, new EventId(21, nameof(DisposingClient)), "Disposing client."); - private static readonly Action _abortingClient = - LoggerMessage.Define(LogLevel.Error, new EventId(22, nameof(AbortingClient)), "{time}: Connection Id {connectionId}: Aborting client."); + private static readonly Action _abortingClient = + LoggerMessage.Define(LogLevel.Error, new EventId(22, nameof(AbortingClient)), "Aborting client."); private static readonly Action _errorDuringClosedEvent = LoggerMessage.Define(LogLevel.Error, new EventId(23, nameof(ErrorDuringClosedEvent)), "An exception was thrown in the handler for the Closed event."); - private static readonly Action _skippingStop = - LoggerMessage.Define(LogLevel.Debug, new EventId(24, nameof(SkippingStop)), "{time}: Connection Id {connectionId}: Skipping stop, connection is already stopped."); + private static readonly Action _skippingStop = + LoggerMessage.Define(LogLevel.Debug, new EventId(24, nameof(SkippingStop)), "Skipping stop, connection is already stopped."); - private static readonly Action _skippingDispose = - LoggerMessage.Define(LogLevel.Debug, new EventId(25, nameof(SkippingDispose)), "{time}: Connection Id {connectionId}: Skipping dispose, connection is already disposed."); + private static readonly Action _skippingDispose = + LoggerMessage.Define(LogLevel.Debug, new EventId(25, nameof(SkippingDispose)), "Skipping dispose, connection is already disposed."); - private static readonly Action _connectionStateChanged = - LoggerMessage.Define(LogLevel.Debug, new EventId(26, nameof(ConnectionStateChanged)), "{time}: Connection Id {connectionId}: Connection state changed from {previousState} to {newState}."); + private static readonly Action _connectionStateChanged = + LoggerMessage.Define(LogLevel.Debug, new EventId(26, nameof(ConnectionStateChanged)), "Connection state changed from {previousState} to {newState}."); - public static void StartTransport(this ILogger logger, string connectionId, TransferMode transferMode) + public static void StartTransport(this ILogger logger, TransferMode transferMode) { - if (logger.IsEnabled(LogLevel.Information)) - { - _startTransport(logger, DateTime.Now, connectionId, transferMode, null); - } + _startTransport(logger, transferMode, null); } - public static void TransportStopped(this ILogger logger, string connectionId, Exception exception) + public static void TransportStopped(this ILogger logger, Exception exception) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _transportStopped(logger, DateTime.Now, connectionId, exception); - } + _transportStopped(logger, exception); } - public static void StartReceive(this ILogger logger, string connectionId) + public static void StartReceive(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _startReceive(logger, DateTime.Now, connectionId, null); - } + _startReceive(logger, null); } - public static void TransportStopping(this ILogger logger, string connectionId) + public static void TransportStopping(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Information)) - { - _transportStopping(logger, DateTime.Now, connectionId, null); - } + _transportStopping(logger, null); } - public static void WebSocketClosed(this ILogger logger, string connectionId, WebSocketCloseStatus? closeStatus) + public static void WebSocketClosed(this ILogger logger, WebSocketCloseStatus? closeStatus) { - if (logger.IsEnabled(LogLevel.Information)) - { - _webSocketClosed(logger, DateTime.Now, connectionId, closeStatus, null); - } + _webSocketClosed(logger, closeStatus, null); } - public static void MessageReceived(this ILogger logger, string connectionId, WebSocketMessageType messageType, int count, bool endOfMessage) + public static void MessageReceived(this ILogger logger, WebSocketMessageType messageType, int count, bool endOfMessage) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _messageReceived(logger, DateTime.Now, connectionId, messageType, count, endOfMessage, null); - } + _messageReceived(logger, messageType, count, endOfMessage, null); } - public static void MessageToApp(this ILogger logger, string connectionId, int count) + public static void MessageToApp(this ILogger logger, int count) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _messageToApp(logger, DateTime.Now, connectionId, count, null); - } + _messageToApp(logger, count, null); } - public static void ReceiveCanceled(this ILogger logger, string connectionId) + public static void ReceiveCanceled(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _receiveCanceled(logger, DateTime.Now, connectionId, null); - } + _receiveCanceled(logger, null); } - public static void ReceiveStopped(this ILogger logger, string connectionId) + public static void ReceiveStopped(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _receiveStopped(logger, DateTime.Now, connectionId, null); - } + _receiveStopped(logger, null); } - public static void SendStarted(this ILogger logger, string connectionId) + public static void SendStarted(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _sendStarted(logger, DateTime.Now, connectionId, null); - } + _sendStarted(logger, null); } - public static void ReceivedFromApp(this ILogger logger, string connectionId, int count) + public static void ReceivedFromApp(this ILogger logger, int count) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _receivedFromApp(logger, DateTime.Now, connectionId, count, null); - } + _receivedFromApp(logger, count, null); } - public static void SendMessageCanceled(this ILogger logger, string connectionId) + public static void SendMessageCanceled(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Information)) - { - _sendMessageCanceled(logger, DateTime.Now, connectionId, null); - } + _sendMessageCanceled(logger, null); } - public static void ErrorSendingMessage(this ILogger logger, string connectionId, Exception exception) + public static void ErrorSendingMessage(this ILogger logger, Exception exception) { - if (logger.IsEnabled(LogLevel.Error)) - { - _errorSendingMessage(logger, DateTime.Now, connectionId, exception); - } + _errorSendingMessage(logger, exception); } - public static void SendCanceled(this ILogger logger, string connectionId) + public static void SendCanceled(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _sendCanceled(logger, DateTime.Now, connectionId, null); - } + _sendCanceled(logger, null); } - public static void SendStopped(this ILogger logger, string connectionId) + public static void SendStopped(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _sendStopped(logger, DateTime.Now, connectionId, null); - } + _sendStopped(logger, null); } - public static void ClosingWebSocket(this ILogger logger, string connectionId) + public static void ClosingWebSocket(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Information)) - { - _closingWebSocket(logger, DateTime.Now, connectionId, null); - } + _closingWebSocket(logger, null); } - public static void ClosingWebSocketFailed(this ILogger logger, string connectionId, Exception exception) + public static void ClosingWebSocketFailed(this ILogger logger, Exception exception) { - if (logger.IsEnabled(LogLevel.Information)) - { - _closingWebSocketFailed(logger, DateTime.Now, connectionId, exception); - } + _closingWebSocketFailed(logger, exception); } - public static void CancelMessage(this ILogger logger, string connectionId) + public static void CancelMessage(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _cancelMessage(logger, DateTime.Now, connectionId, null); - } + _cancelMessage(logger, null); } - public static void SendingMessages(this ILogger logger, string connectionId, int count, Uri url) + public static void SendingMessages(this ILogger logger, int count, Uri url) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _sendingMessages(logger, DateTime.Now, connectionId, count, url, null); - } + _sendingMessages(logger, count, url, null); } - public static void SentSuccessfully(this ILogger logger, string connectionId) + public static void SentSuccessfully(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _sentSuccessfully(logger, DateTime.Now, connectionId, null); - } + _sentSuccessfully(logger, null); } - public static void NoMessages(this ILogger logger, string connectionId) + public static void NoMessages(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _noMessages(logger, DateTime.Now, connectionId, null); - } + _noMessages(logger, null); } - public static void ErrorSending(this ILogger logger, string connectionId, Uri url, Exception exception) + public static void ErrorSending(this ILogger logger, Uri url, Exception exception) { - if (logger.IsEnabled(LogLevel.Error)) - { - _errorSending(logger, DateTime.Now, connectionId, url, exception); - } + _errorSending(logger, url, exception); } - public static void EventStreamEnded(this ILogger logger, string connectionId) + public static void EventStreamEnded(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _eventStreamEnded(logger, DateTime.Now, connectionId, null); - } + _eventStreamEnded(logger, null); } - public static void ClosingConnection(this ILogger logger, string connectionId) + public static void ClosingConnection(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _closingConnection(logger, DateTime.Now, connectionId, null); - } + _closingConnection(logger, null); } - public static void ReceivedMessages(this ILogger logger, string connectionId) + public static void ReceivedMessages(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _receivedMessages(logger, DateTime.Now, connectionId, null); - } + _receivedMessages(logger, null); } - public static void ErrorPolling(this ILogger logger, string connectionId, Uri pollUrl, Exception exception) + public static void ErrorPolling(this ILogger logger, Uri pollUrl, Exception exception) { - if (logger.IsEnabled(LogLevel.Error)) - { - _errorPolling(logger, DateTime.Now, connectionId, pollUrl, exception); - } + _errorPolling(logger, pollUrl, exception); } public static void HttpConnectionStarting(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _httpConnectionStarting(logger, DateTime.Now, null); - } + _httpConnectionStarting(logger, null); } - public static void HttpConnectionClosed(this ILogger logger, string connectionId) + public static void HttpConnectionClosed(this ILogger logger) + { + _httpConnectionClosed(logger, null); + } + + public static void StartingTransport(this ILogger logger, ITransport transport, Uri url) { if (logger.IsEnabled(LogLevel.Debug)) { - _httpConnectionClosed(logger, DateTime.Now, connectionId, null); + _startingTransport(logger, transport.GetType().Name, url, null); } } - public static void StartingTransport(this ILogger logger, string connectionId, string transport, Uri url) + public static void RaiseConnected(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _startingTransport(logger, DateTime.Now, connectionId, transport, url, null); - } + _raiseConnected(logger, null); } - public static void RaiseConnected(this ILogger logger, string connectionId) + public static void ProcessRemainingMessages(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _raiseConnected(logger, DateTime.Now, connectionId, null); - } + _processRemainingMessages(logger, null); } - public static void ProcessRemainingMessages(this ILogger logger, string connectionId) + public static void DrainEvents(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _processRemainingMessages(logger, DateTime.Now, connectionId, null); - } + _drainEvents(logger, null); } - public static void DrainEvents(this ILogger logger, string connectionId) + public static void CompleteClosed(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _drainEvents(logger, DateTime.Now, connectionId, null); - } - } - - public static void CompleteClosed(this ILogger logger, string connectionId) - { - if (logger.IsEnabled(LogLevel.Debug)) - { - _completeClosed(logger, DateTime.Now, connectionId, null); - } + _completeClosed(logger, null); } public static void EstablishingConnection(this ILogger logger, Uri url) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _establishingConnection(logger, DateTime.Now, url, null); - } + _establishingConnection(logger, url, null); } public static void ErrorWithNegotiation(this ILogger logger, Uri url, Exception exception) { - if (logger.IsEnabled(LogLevel.Error)) - { - _errorWithNegotiation(logger, DateTime.Now, url, exception); - } + _errorWithNegotiation(logger, url, exception); } - public static void ErrorStartingTransport(this ILogger logger, string connectionId, string transport, Exception exception) + public static void ErrorStartingTransport(this ILogger logger, ITransport transport, Exception exception) { if (logger.IsEnabled(LogLevel.Error)) { - _errorStartingTransport(logger, DateTime.Now, connectionId, transport, exception); + _errorStartingTransport(logger, transport.GetType().Name, exception); } } - public static void HttpReceiveStarted(this ILogger logger, string connectionId) + public static void HttpReceiveStarted(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Trace)) - { - _httpReceiveStarted(logger, DateTime.Now, connectionId, null); - } + _httpReceiveStarted(logger, null); } - public static void SkipRaisingReceiveEvent(this ILogger logger, string connectionId) + public static void SkipRaisingReceiveEvent(this ILogger logger) + { + _skipRaisingReceiveEvent(logger, null); + } + + public static void ScheduleReceiveEvent(this ILogger logger) + { + _scheduleReceiveEvent(logger, null); + } + + public static void RaiseReceiveEvent(this ILogger logger) + { + _raiseReceiveEvent(logger, null); + } + + public static void FailedReadingMessage(this ILogger logger) + { + _failedReadingMessage(logger, null); + } + + public static void ErrorReceiving(this ILogger logger, Exception exception) + { + _errorReceiving(logger, exception); + } + + public static void EndReceive(this ILogger logger) + { + _endReceive(logger, null); + } + + public static void SendingMessage(this ILogger logger) + { + _sendingMessage(logger, null); + } + + public static void AbortingClient(this ILogger logger, Exception ex) + { + _abortingClient(logger, ex); + } + + public static void StoppingClient(this ILogger logger) + { + _stoppingClient(logger, null); + } + + public static void DisposingClient(this ILogger logger) + { + _disposingClient(logger, null); + } + + public static void SkippingDispose(this ILogger logger) + { + _skippingDispose(logger, null); + } + + public static void ConnectionStateChanged(this ILogger logger, HttpConnection.ConnectionState previousState, HttpConnection.ConnectionState newState) { if (logger.IsEnabled(LogLevel.Debug)) { - _skipRaisingReceiveEvent(logger, DateTime.Now, connectionId, null); + _connectionStateChanged(logger, previousState.ToString(), newState.ToString(), null); } } - public static void ScheduleReceiveEvent(this ILogger logger, string connectionId) + public static void SkippingStop(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _scheduleReceiveEvent(logger, DateTime.Now, connectionId, null); - } + _skippingStop(logger, null); } - public static void RaiseReceiveEvent(this ILogger logger, string connectionId) + public static void ExceptionThrownFromCallback(this ILogger logger, string callbackName, Exception exception) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _raiseReceiveEvent(logger, DateTime.Now, connectionId, null); - } - } - - public static void FailedReadingMessage(this ILogger logger, string connectionId) - { - if (logger.IsEnabled(LogLevel.Debug)) - { - _failedReadingMessage(logger, DateTime.Now, connectionId, null); - } - } - - public static void ErrorReceiving(this ILogger logger, string connectionId, Exception exception) - { - if (logger.IsEnabled(LogLevel.Error)) - { - _errorReceiving(logger, DateTime.Now, connectionId, exception); - } - } - - public static void EndReceive(this ILogger logger, string connectionId) - { - if (logger.IsEnabled(LogLevel.Trace)) - { - _endReceive(logger, DateTime.Now, connectionId, null); - } - } - - public static void SendingMessage(this ILogger logger, string connectionId) - { - if (logger.IsEnabled(LogLevel.Debug)) - { - _sendingMessage(logger, DateTime.Now, connectionId, null); - } - } - - public static void AbortingClient(this ILogger logger, string connectionId, Exception ex) - { - if (logger.IsEnabled(LogLevel.Error)) - { - _abortingClient(logger, DateTime.Now, connectionId, ex); - } - } - - public static void StoppingClient(this ILogger logger, string connectionId) - { - if (logger.IsEnabled(LogLevel.Information)) - { - _stoppingClient(logger, DateTime.Now, connectionId, null); - } - } - - public static void DisposingClient(this ILogger logger, string connectionId) - { - if (logger.IsEnabled(LogLevel.Information)) - { - _disposingClient(logger, DateTime.Now, connectionId, null); - } - } - - public static void SkippingDispose(this ILogger logger, string connectionId) - { - if (logger.IsEnabled(LogLevel.Debug)) - { - _skippingDispose(logger, DateTime.Now, connectionId, null); - } - } - - public static void ConnectionStateChanged(this ILogger logger, string connectionId, HttpConnection.ConnectionState previousState, HttpConnection.ConnectionState newState) - { - if (logger.IsEnabled(LogLevel.Debug)) - { - _connectionStateChanged(logger, DateTime.Now, connectionId, previousState.ToString(), newState.ToString(), null); - } - } - - public static void SkippingStop(this ILogger logger, string connectionId) - { - if (logger.IsEnabled(LogLevel.Debug)) - { - _skippingStop(logger, DateTime.Now, connectionId, null); - } - } - - public static void ExceptionThrownFromCallback(this ILogger logger, string connectionId, string callbackName, Exception exception) - { - if (logger.IsEnabled(LogLevel.Error)) - { - _exceptionThrownFromCallback(logger, DateTime.Now, connectionId, callbackName, exception); - } + _exceptionThrownFromCallback(logger, callbackName, exception); } public static void ErrorDuringClosedEvent(this ILogger logger, Exception exception) diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/LongPollingTransport.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/LongPollingTransport.cs index 5135a8a56c..0dfc8135e9 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/LongPollingTransport.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/LongPollingTransport.cs @@ -23,7 +23,6 @@ namespace Microsoft.AspNetCore.Sockets.Client private Channel _application; private Task _sender; private Task _poller; - private string _connectionId; private readonly CancellationTokenSource _transportCts = new CancellationTokenSource(); @@ -42,7 +41,7 @@ namespace Microsoft.AspNetCore.Sockets.Client _logger = (loggerFactory ?? NullLoggerFactory.Instance).CreateLogger(); } - public Task StartAsync(Uri url, Channel application, TransferMode requestedTransferMode, string connectionId, IConnection connection) + public Task StartAsync(Uri url, Channel application, TransferMode requestedTransferMode, IConnection connection) { if (requestedTransferMode != TransferMode.Binary && requestedTransferMode != TransferMode.Text) { @@ -53,17 +52,16 @@ namespace Microsoft.AspNetCore.Sockets.Client _application = application; Mode = requestedTransferMode; - _connectionId = connectionId; - _logger.StartTransport(_connectionId, Mode.Value); + _logger.StartTransport(Mode.Value); // Start sending and polling (ask for binary if the server supports it) _poller = Poll(url, _transportCts.Token); - _sender = SendUtils.SendMessages(url, _application, _httpClient, _httpOptions, _transportCts, _logger, _connectionId); + _sender = SendUtils.SendMessages(url, _application, _httpClient, _httpOptions, _transportCts, _logger); Running = Task.WhenAll(_sender, _poller).ContinueWith(t => { - _logger.TransportStopped(_connectionId, t.Exception?.InnerException); + _logger.TransportStopped(t.Exception?.InnerException); _application.Writer.TryComplete(t.IsFaulted ? t.Exception.InnerException : null); return t; }).Unwrap(); @@ -73,7 +71,7 @@ namespace Microsoft.AspNetCore.Sockets.Client public async Task StopAsync() { - _logger.TransportStopping(_connectionId); + _logger.TransportStopping(); _transportCts.Cancel(); @@ -89,7 +87,7 @@ namespace Microsoft.AspNetCore.Sockets.Client private async Task Poll(Uri pollUrl, CancellationToken cancellationToken) { - _logger.StartReceive(_connectionId); + _logger.StartReceive(); try { while (!cancellationToken.IsCancellationRequested) @@ -115,14 +113,14 @@ namespace Microsoft.AspNetCore.Sockets.Client if (response.StatusCode == HttpStatusCode.NoContent || cancellationToken.IsCancellationRequested) { - _logger.ClosingConnection(_connectionId); + _logger.ClosingConnection(); // Transport closed or polling stopped, we're done break; } else { - _logger.ReceivedMessages(_connectionId); + _logger.ReceivedMessages(); // Until Pipeline starts natively supporting BytesReader, this is the easiest way to do this. var payload = await response.Content.ReadAsByteArrayAsync(); @@ -142,18 +140,18 @@ namespace Microsoft.AspNetCore.Sockets.Client catch (OperationCanceledException) { // transport is being closed - _logger.ReceiveCanceled(_connectionId); + _logger.ReceiveCanceled(); } catch (Exception ex) { - _logger.ErrorPolling(_connectionId, pollUrl, ex); + _logger.ErrorPolling(pollUrl, ex); throw; } finally { // Make sure the send loop is terminated _transportCts.Cancel(); - _logger.ReceiveStopped(_connectionId); + _logger.ReceiveStopped(); } } } diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/SendUtils.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/SendUtils.cs index 023054ab30..7c5e6b7d1e 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/SendUtils.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/SendUtils.cs @@ -17,9 +17,9 @@ namespace Microsoft.AspNetCore.Sockets.Client internal static class SendUtils { public static async Task SendMessages(Uri sendUrl, Channel application, HttpClient httpClient, - HttpOptions httpOptions, CancellationTokenSource transportCts, ILogger logger, string connectionId) + HttpOptions httpOptions, CancellationTokenSource transportCts, ILogger logger) { - logger.SendStarted(connectionId); + logger.SendStarted(); IList messages = null; try { @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Sockets.Client transportCts.Token.ThrowIfCancellationRequested(); if (messages.Count > 0) { - logger.SendingMessages(connectionId, messages.Count, sendUrl); + logger.SendingMessages(messages.Count, sendUrl); // Send them in a single post var request = new HttpRequestMessage(HttpMethod.Post, sendUrl); @@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Sockets.Client var response = await httpClient.SendAsync(request, transportCts.Token); response.EnsureSuccessStatusCode(); - logger.SentSuccessfully(connectionId); + logger.SentSuccessfully(); foreach (var message in messages) { message.SendResult?.TrySetResult(null); @@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Sockets.Client } else { - logger.NoMessages(connectionId); + logger.NoMessages(); } } } @@ -84,11 +84,11 @@ namespace Microsoft.AspNetCore.Sockets.Client message.SendResult?.TrySetCanceled(); } } - logger.SendCanceled(connectionId); + logger.SendCanceled(); } catch (Exception ex) { - logger.ErrorSending(connectionId, sendUrl, ex); + logger.ErrorSending(sendUrl, ex); if (messages != null) { foreach (var message in messages) @@ -105,7 +105,7 @@ namespace Microsoft.AspNetCore.Sockets.Client transportCts.Cancel(); } - logger.SendStopped(connectionId); + logger.SendStopped(); } public static void PrepareHttpRequest(HttpRequestMessage request, HttpOptions httpOptions) diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/ServerSentEventsTransport.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/ServerSentEventsTransport.cs index c0c5b929cd..ae0340d5bf 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/ServerSentEventsTransport.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/ServerSentEventsTransport.cs @@ -25,7 +25,6 @@ namespace Microsoft.AspNetCore.Sockets.Client private readonly ILogger _logger; private readonly CancellationTokenSource _transportCts = new CancellationTokenSource(); private readonly ServerSentEventsMessageParser _parser = new ServerSentEventsMessageParser(); - private string _connectionId; private Channel _application; @@ -49,7 +48,7 @@ namespace Microsoft.AspNetCore.Sockets.Client _logger = (loggerFactory ?? NullLoggerFactory.Instance).CreateLogger(); } - public Task StartAsync(Uri url, Channel application, TransferMode requestedTransferMode, string connectionId, IConnection connection) + public Task StartAsync(Uri url, Channel application, TransferMode requestedTransferMode, IConnection connection) { if (requestedTransferMode != TransferMode.Binary && requestedTransferMode != TransferMode.Text) { @@ -58,16 +57,15 @@ namespace Microsoft.AspNetCore.Sockets.Client _application = application; Mode = TransferMode.Text; // Server Sent Events is a text only transport - _connectionId = connectionId; - _logger.StartTransport(_connectionId, Mode.Value); + _logger.StartTransport(Mode.Value); - var sendTask = SendUtils.SendMessages(url, _application, _httpClient, _httpOptions, _transportCts, _logger, _connectionId); + var sendTask = SendUtils.SendMessages(url, _application, _httpClient, _httpOptions, _transportCts, _logger); var receiveTask = OpenConnection(_application, url, _transportCts.Token); Running = Task.WhenAll(sendTask, receiveTask).ContinueWith(t => { - _logger.TransportStopped(_connectionId, t.Exception?.InnerException); + _logger.TransportStopped(t.Exception?.InnerException); _application.Writer.TryComplete(t.IsFaulted ? t.Exception.InnerException : null); return t; @@ -78,7 +76,7 @@ namespace Microsoft.AspNetCore.Sockets.Client private async Task OpenConnection(Channel application, Uri url, CancellationToken cancellationToken) { - _logger.StartReceive(_connectionId); + _logger.StartReceive(); var request = new HttpRequestMessage(HttpMethod.Get, url); SendUtils.PrepareHttpRequest(request, _httpOptions); @@ -97,7 +95,7 @@ namespace Microsoft.AspNetCore.Sockets.Client var input = result.Buffer; if (result.IsCancelled || (input.IsEmpty && result.IsCompleted)) { - _logger.EventStreamEnded(_connectionId); + _logger.EventStreamEnded(); break; } @@ -130,20 +128,20 @@ namespace Microsoft.AspNetCore.Sockets.Client } catch (OperationCanceledException) { - _logger.ReceiveCanceled(_connectionId); + _logger.ReceiveCanceled(); } finally { readCancellationRegistration.Dispose(); _transportCts.Cancel(); stream.Dispose(); - _logger.ReceiveStopped(_connectionId); + _logger.ReceiveStopped(); } } public async Task StopAsync() { - _logger.TransportStopping(_connectionId); + _logger.TransportStopping(); _transportCts.Cancel(); _application.Writer.TryComplete(); diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/WebSocketsTransport.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/WebSocketsTransport.cs index f68c2d8b37..377f9c2db6 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/WebSocketsTransport.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/WebSocketsTransport.cs @@ -22,7 +22,6 @@ namespace Microsoft.AspNetCore.Sockets.Client private readonly CancellationTokenSource _transportCts = new CancellationTokenSource(); private readonly CancellationTokenSource _receiveCts = new CancellationTokenSource(); private readonly ILogger _logger; - private string _connectionId; public Task Running { get; private set; } = Task.CompletedTask; @@ -55,7 +54,7 @@ namespace Microsoft.AspNetCore.Sockets.Client _logger = (loggerFactory ?? NullLoggerFactory.Instance).CreateLogger(); } - public async Task StartAsync(Uri url, Channel application, TransferMode requestedTransferMode, string connectionId, IConnection connection) + public async Task StartAsync(Uri url, Channel application, TransferMode requestedTransferMode, IConnection connection) { if (url == null) { @@ -74,9 +73,8 @@ namespace Microsoft.AspNetCore.Sockets.Client _application = application; Mode = requestedTransferMode; - _connectionId = connectionId; - _logger.StartTransport(_connectionId, Mode.Value); + _logger.StartTransport(Mode.Value); await Connect(url); var sendTask = SendMessages(url); @@ -87,7 +85,7 @@ namespace Microsoft.AspNetCore.Sockets.Client Running = Task.WhenAll(sendTask, receiveTask).ContinueWith(t => { _webSocket.Dispose(); - _logger.TransportStopped(_connectionId, t.Exception?.InnerException); + _logger.TransportStopped(t.Exception?.InnerException); _application.Writer.TryComplete(t.IsFaulted ? t.Exception.InnerException : null); return t; }).Unwrap(); @@ -95,7 +93,7 @@ namespace Microsoft.AspNetCore.Sockets.Client private async Task ReceiveMessages(Uri pollUrl) { - _logger.StartReceive(_connectionId); + _logger.StartReceive(); try { @@ -113,7 +111,7 @@ namespace Microsoft.AspNetCore.Sockets.Client receiveResult = await _webSocket.ReceiveAsync(buffer, _receiveCts.Token); if (receiveResult.MessageType == WebSocketMessageType.Close) { - _logger.WebSocketClosed(_connectionId, receiveResult.CloseStatus); + _logger.WebSocketClosed(receiveResult.CloseStatus); _application.Writer.Complete( receiveResult.CloseStatus == WebSocketCloseStatus.NormalClosure @@ -123,7 +121,7 @@ namespace Microsoft.AspNetCore.Sockets.Client return; } - _logger.MessageReceived(_connectionId, receiveResult.MessageType, receiveResult.Count, receiveResult.EndOfMessage); + _logger.MessageReceived(receiveResult.MessageType, receiveResult.Count, receiveResult.EndOfMessage); var truncBuffer = new ArraySegment(buffer.Array, 0, receiveResult.Count); incomingMessage.Add(truncBuffer); @@ -152,7 +150,7 @@ namespace Microsoft.AspNetCore.Sockets.Client { if (!_transportCts.Token.IsCancellationRequested) { - _logger.MessageToApp(_connectionId, messageBuffer.Length); + _logger.MessageToApp(messageBuffer.Length); while (await _application.Writer.WaitToWriteAsync(_transportCts.Token)) { if (_application.Writer.TryWrite(messageBuffer)) @@ -165,24 +163,24 @@ namespace Microsoft.AspNetCore.Sockets.Client } catch (OperationCanceledException) { - _logger.CancelMessage(_connectionId); + _logger.CancelMessage(); } } } catch (OperationCanceledException) { - _logger.ReceiveCanceled(_connectionId); + _logger.ReceiveCanceled(); } finally { - _logger.ReceiveStopped(_connectionId); + _logger.ReceiveStopped(); _transportCts.Cancel(); } } private async Task SendMessages(Uri sendUrl) { - _logger.SendStarted(_connectionId); + _logger.SendStarted(); var webSocketMessageType = Mode == TransferMode.Binary @@ -197,7 +195,7 @@ namespace Microsoft.AspNetCore.Sockets.Client { try { - _logger.ReceivedFromApp(_connectionId, message.Payload.Length); + _logger.ReceivedFromApp(message.Payload.Length); await _webSocket.SendAsync(new ArraySegment(message.Payload), webSocketMessageType, true, _transportCts.Token); @@ -205,14 +203,14 @@ namespace Microsoft.AspNetCore.Sockets.Client } catch (OperationCanceledException) { - _logger.SendMessageCanceled(_connectionId); + _logger.SendMessageCanceled(); message.SendResult.SetCanceled(); await CloseWebSocket(); break; } catch (Exception ex) { - _logger.ErrorSendingMessage(_connectionId, ex); + _logger.ErrorSendingMessage(ex); message.SendResult.SetException(ex); await CloseWebSocket(); throw; @@ -222,11 +220,11 @@ namespace Microsoft.AspNetCore.Sockets.Client } catch (OperationCanceledException) { - _logger.SendCanceled(_connectionId); + _logger.SendCanceled(); } finally { - _logger.SendStopped(_connectionId); + _logger.SendStopped(); TriggerCancel(); } } @@ -248,7 +246,7 @@ namespace Microsoft.AspNetCore.Sockets.Client public async Task StopAsync() { - _logger.TransportStopping(_connectionId); + _logger.TransportStopping(); await CloseWebSocket(); @@ -270,7 +268,7 @@ namespace Microsoft.AspNetCore.Sockets.Client // while the webSocket is being closed due to an error. if (_webSocket.State != WebSocketState.Closed) { - _logger.ClosingWebSocket(_connectionId); + _logger.ClosingWebSocket(); // We intentionally don't pass _transportCts.Token to CloseOutputAsync. The token can be cancelled // for reasons not related to webSocket in which case we would not close the websocket gracefully. @@ -284,7 +282,7 @@ namespace Microsoft.AspNetCore.Sockets.Client { // This is benign - the exception can happen due to the race described above because we would // try closing the webSocket twice. - _logger.ClosingWebSocketFailed(_connectionId, ex); + _logger.ClosingWebSocketFailed(ex); } } diff --git a/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionDispatcher.cs b/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionDispatcher.cs index 1e38564a3e..5ea1703fb8 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionDispatcher.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionDispatcher.cs @@ -109,7 +109,7 @@ namespace Microsoft.AspNetCore.Sockets return; } - _logger.EstablishedConnection(connection.ConnectionId, context.TraceIdentifier); + _logger.EstablishedConnection(); // ServerSentEvents is a text protocol only connection.TransportCapabilities = TransferMode.Text; @@ -135,7 +135,7 @@ namespace Microsoft.AspNetCore.Sockets return; } - _logger.EstablishedConnection(connection.ConnectionId, context.TraceIdentifier); + _logger.EstablishedConnection(); var ws = new WebSocketsTransport(options.WebSockets, connection.Application, connection, _loggerFactory); @@ -196,7 +196,7 @@ namespace Microsoft.AspNetCore.Sockets // Raise OnConnected for new connections only since polls happen all the time if (connection.ApplicationTask == null) { - _logger.EstablishedConnection(connection.ConnectionId, connection.GetHttpContext().TraceIdentifier); + _logger.EstablishedConnection(); connection.Metadata[ConnectionMetadataNames.Transport] = TransportType.LongPolling; @@ -204,7 +204,7 @@ namespace Microsoft.AspNetCore.Sockets } else { - _logger.ResumingConnection(connection.ConnectionId, connection.GetHttpContext().TraceIdentifier); + _logger.ResumingConnection(); } // REVIEW: Performance of this isn't great as this does a bunch of per request allocations @@ -370,7 +370,7 @@ namespace Microsoft.AspNetCore.Sockets // Get the bytes for the connection id var negotiateResponseBuffer = Encoding.UTF8.GetBytes(GetNegotiatePayload(connection.ConnectionId, options)); - _logger.NegotiationRequest(connection.ConnectionId); + _logger.NegotiationRequest(); // Write it out to the response with the right content length context.Response.ContentLength = negotiateResponseBuffer.Length; @@ -422,7 +422,7 @@ namespace Microsoft.AspNetCore.Sockets var transport = (TransportType?)connection.Metadata[ConnectionMetadataNames.Transport]; if (transport == TransportType.WebSockets) { - _logger.PostNotAllowedForWebSockets(connection.ConnectionId); + _logger.PostNotAllowedForWebSockets(); context.Response.StatusCode = StatusCodes.Status405MethodNotAllowed; await context.Response.WriteAsync("POST requests are not allowed for WebSocket connections."); return; @@ -438,7 +438,7 @@ namespace Microsoft.AspNetCore.Sockets buffer = stream.ToArray(); } - _logger.ReceivedBytes(connection.ConnectionId, buffer.Length); + _logger.ReceivedBytes(buffer.Length); while (!connection.Application.Writer.TryWrite(buffer)) { if (!await connection.Application.Writer.WaitToWriteAsync()) @@ -454,7 +454,7 @@ namespace Microsoft.AspNetCore.Sockets { context.Response.ContentType = "text/plain"; context.Response.StatusCode = StatusCodes.Status404NotFound; - _logger.TransportNotSupported(connection.ConnectionId, transportType); + _logger.TransportNotSupported(transportType); await context.Response.WriteAsync($"{transportType} transport not supported by this end point type"); return false; } @@ -469,7 +469,7 @@ namespace Microsoft.AspNetCore.Sockets { context.Response.ContentType = "text/plain"; context.Response.StatusCode = StatusCodes.Status400BadRequest; - _logger.CannotChangeTransport(connection.ConnectionId, transport.Value, transportType); + _logger.CannotChangeTransport(transport.Value, transportType); await context.Response.WriteAsync("Cannot change transports mid-connection"); return false; } diff --git a/src/Microsoft.AspNetCore.Sockets.Http/Internal/SocketHttpLoggerExtensions.cs b/src/Microsoft.AspNetCore.Sockets.Http/Internal/SocketHttpLoggerExtensions.cs index 8d10035d20..890816b7de 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/Internal/SocketHttpLoggerExtensions.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/Internal/SocketHttpLoggerExtensions.cs @@ -10,326 +10,239 @@ namespace Microsoft.AspNetCore.Sockets.Internal internal static class SocketHttpLoggerExtensions { // Category: LongPollingTransport - private static readonly Action _longPolling204 = - LoggerMessage.Define(LogLevel.Information, new EventId(1, nameof(LongPolling204)), "{time}: Connection Id {connectionId}, Request Id {requestId}: Terminating Long Polling connection by sending 204 response."); + private static readonly Action _longPolling204 = + LoggerMessage.Define(LogLevel.Information, new EventId(1, nameof(LongPolling204)), "Terminating Long Polling connection by sending 204 response."); - private static readonly Action _pollTimedOut = - LoggerMessage.Define(LogLevel.Information, new EventId(2, nameof(PollTimedOut)), "{time}: Connection Id {connectionId}, Request Id {requestId}: Poll request timed out. Sending 200 response to connection."); + private static readonly Action _pollTimedOut = + LoggerMessage.Define(LogLevel.Information, new EventId(2, nameof(PollTimedOut)), "Poll request timed out. Sending 200 response to connection."); - private static readonly Action _longPollingWritingMessage = - LoggerMessage.Define(LogLevel.Debug, new EventId(3, nameof(LongPollingWritingMessage)), "{time}: Connection Id {connectionId}, Request Id {requestId}: Writing a {count} byte message to connection."); + private static readonly Action _longPollingWritingMessage = + LoggerMessage.Define(LogLevel.Debug, new EventId(3, nameof(LongPollingWritingMessage)), "Writing a {count} byte message to connection."); - private static readonly Action _longPollingDisconnected = - LoggerMessage.Define(LogLevel.Debug, new EventId(4, nameof(LongPollingDisconnected)), "{time}: Connection Id {connectionId}, Request Id {requestId}: Client disconnected from Long Polling endpoint for connection."); + private static readonly Action _longPollingDisconnected = + LoggerMessage.Define(LogLevel.Debug, new EventId(4, nameof(LongPollingDisconnected)), "Client disconnected from Long Polling endpoint for connection."); - private static readonly Action _longPollingTerminated = - LoggerMessage.Define(LogLevel.Error, new EventId(5, nameof(LongPollingTerminated)), "{time}: Connection Id {connectionId}, Request Id {requestId}: Long Polling transport was terminated due to an error on connection."); + private static readonly Action _longPollingTerminated = + LoggerMessage.Define(LogLevel.Error, new EventId(5, nameof(LongPollingTerminated)), "Long Polling transport was terminated due to an error on connection."); // Category: HttpConnectionDispatcher - private static readonly Action _connectionDisposed = - LoggerMessage.Define(LogLevel.Debug, new EventId(1, nameof(ConnectionDisposed)), "{time}: Connection Id {connectionId} was disposed."); + private static readonly Action _connectionDisposed = + LoggerMessage.Define(LogLevel.Debug, new EventId(1, nameof(ConnectionDisposed)), "Connection Id {connectionId} was disposed."); - private static readonly Action _connectionAlreadyActive = - LoggerMessage.Define(LogLevel.Debug, new EventId(2, nameof(ConnectionAlreadyActive)), "{time}: Connection Id {connectionId} is already active via {requestId}."); + private static readonly Action _connectionAlreadyActive = + LoggerMessage.Define(LogLevel.Debug, new EventId(2, nameof(ConnectionAlreadyActive)), "Connection Id {connectionId} is already active via {requestId}."); - private static readonly Action _pollCanceled = - LoggerMessage.Define(LogLevel.Debug, new EventId(3, nameof(PollCanceled)), "{time}: Previous poll canceled for {connectionId} on {requestId}."); + private static readonly Action _pollCanceled = + LoggerMessage.Define(LogLevel.Debug, new EventId(3, nameof(PollCanceled)), "Previous poll canceled for {connectionId} on {requestId}."); - private static readonly Action _establishedConnection = - LoggerMessage.Define(LogLevel.Debug, new EventId(4, nameof(EstablishedConnection)), "{time}: Connection Id {connectionId}, Request Id {requestId}: Establishing new connection."); + private static readonly Action _establishedConnection = + LoggerMessage.Define(LogLevel.Debug, new EventId(4, nameof(EstablishedConnection)), "Establishing new connection."); - private static readonly Action _resumingConnection = - LoggerMessage.Define(LogLevel.Debug, new EventId(5, nameof(ResumingConnection)), "{time}: Connection Id {connectionId}, Request Id {requestId}: Resuming existing connection."); + private static readonly Action _resumingConnection = + LoggerMessage.Define(LogLevel.Debug, new EventId(5, nameof(ResumingConnection)), "Resuming existing connection."); - private static readonly Action _receivedBytes = - LoggerMessage.Define(LogLevel.Debug, new EventId(6, nameof(ReceivedBytes)), "{time}: Connection Id {connectionId}: Received {count} bytes."); + private static readonly Action _receivedBytes = + LoggerMessage.Define(LogLevel.Debug, new EventId(6, nameof(ReceivedBytes)), "Received {count} bytes."); - private static readonly Action _transportNotSupported = - LoggerMessage.Define(LogLevel.Debug, new EventId(7, nameof(TransportNotSupported)), "{time}: Connection Id {connectionId}: {transportType} transport not supported by this endpoint type."); + private static readonly Action _transportNotSupported = + LoggerMessage.Define(LogLevel.Debug, new EventId(7, nameof(TransportNotSupported)), "{transportType} transport not supported by this endpoint type."); - private static readonly Action _cannotChangeTransport = - LoggerMessage.Define(LogLevel.Debug, new EventId(8, nameof(CannotChangeTransport)), "{time}: Connection Id {connectionId}: Cannot change transports mid-connection; currently using {transportType}, requesting {requestedTransport}."); + private static readonly Action _cannotChangeTransport = + LoggerMessage.Define(LogLevel.Debug, new EventId(8, nameof(CannotChangeTransport)), "Cannot change transports mid-connection; currently using {transportType}, requesting {requestedTransport}."); - private static readonly Action _postNotallowedForWebsockets = - LoggerMessage.Define(LogLevel.Debug, new EventId(9, nameof(PostNotAllowedForWebSockets)), "{time}: Connection Id {connectionId}: POST requests are not allowed for websocket connections."); + private static readonly Action _postNotallowedForWebsockets = + LoggerMessage.Define(LogLevel.Debug, new EventId(9, nameof(PostNotAllowedForWebSockets)), "POST requests are not allowed for websocket connections."); - private static readonly Action _negotiationRequest = - LoggerMessage.Define(LogLevel.Debug, new EventId(10, nameof(NegotiationRequest)), "{time}: Connection Id {connectionId}: Sending negotiation response."); + private static readonly Action _negotiationRequest = + LoggerMessage.Define(LogLevel.Debug, new EventId(10, nameof(NegotiationRequest)), "Sending negotiation response."); // Category: WebSocketsTransport - private static readonly Action _socketOpened = - LoggerMessage.Define(LogLevel.Information, new EventId(1, nameof(SocketOpened)), "{time}: Connection Id {connectionId}: Socket opened."); + private static readonly Action _socketOpened = + LoggerMessage.Define(LogLevel.Information, new EventId(1, nameof(SocketOpened)), "Socket opened."); - private static readonly Action _socketClosed = - LoggerMessage.Define(LogLevel.Information, new EventId(2, nameof(SocketClosed)), "{time}: Connection Id {connectionId}: Socket closed."); + private static readonly Action _socketClosed = + LoggerMessage.Define(LogLevel.Information, new EventId(2, nameof(SocketClosed)), "Socket closed."); - private static readonly Action _clientClosed = - LoggerMessage.Define(LogLevel.Debug, new EventId(3, nameof(ClientClosed)), "{time}: Connection Id {connectionId}: Client closed connection with status code '{status}' ({description}). Signaling end-of-input to application."); + private static readonly Action _clientClosed = + LoggerMessage.Define(LogLevel.Debug, new EventId(3, nameof(ClientClosed)), "Client closed connection with status code '{status}' ({description}). Signaling end-of-input to application."); - private static readonly Action _waitingForSend = - LoggerMessage.Define(LogLevel.Debug, new EventId(4, nameof(WaitingForSend)), "{time}: Connection Id {connectionId}: Waiting for the application to finish sending data."); + private static readonly Action _waitingForSend = + LoggerMessage.Define(LogLevel.Debug, new EventId(4, nameof(WaitingForSend)), "Waiting for the application to finish sending data."); - private static readonly Action _failedSending = - LoggerMessage.Define(LogLevel.Debug, new EventId(5, nameof(FailedSending)), "{time}: Connection Id {connectionId}: Application failed during sending. Sending InternalServerError close frame."); + private static readonly Action _failedSending = + LoggerMessage.Define(LogLevel.Debug, new EventId(5, nameof(FailedSending)), "Application failed during sending. Sending InternalServerError close frame."); - private static readonly Action _finishedSending = - LoggerMessage.Define(LogLevel.Debug, new EventId(6, nameof(FinishedSending)), "{time}: Connection Id {connectionId}: Application finished sending. Sending close frame."); + private static readonly Action _finishedSending = + LoggerMessage.Define(LogLevel.Debug, new EventId(6, nameof(FinishedSending)), "Application finished sending. Sending close frame."); - private static readonly Action _waitingForClose = - LoggerMessage.Define(LogLevel.Debug, new EventId(7, nameof(WaitingForClose)), "{time}: Connection Id {connectionId}: Waiting for the client to close the socket."); + private static readonly Action _waitingForClose = + LoggerMessage.Define(LogLevel.Debug, new EventId(7, nameof(WaitingForClose)), "Waiting for the client to close the socket."); - private static readonly Action _closeTimedOut = - LoggerMessage.Define(LogLevel.Debug, new EventId(8, nameof(CloseTimedOut)), "{time}: Connection Id {connectionId}: Timed out waiting for client to send the close frame, aborting the connection."); + private static readonly Action _closeTimedOut = + LoggerMessage.Define(LogLevel.Debug, new EventId(8, nameof(CloseTimedOut)), "Timed out waiting for client to send the close frame, aborting the connection."); - private static readonly Action _messageReceived = - LoggerMessage.Define(LogLevel.Debug, new EventId(9, nameof(MessageReceived)), "{time}: Connection Id {connectionId}: Message received. Type: {messageType}, size: {size}, EndOfMessage: {endOfMessage}."); + private static readonly Action _messageReceived = + LoggerMessage.Define(LogLevel.Debug, new EventId(9, nameof(MessageReceived)), "Message received. Type: {messageType}, size: {size}, EndOfMessage: {endOfMessage}."); - private static readonly Action _messageToApplication = - LoggerMessage.Define(LogLevel.Debug, new EventId(10, nameof(MessageToApplication)), "{time}: Connection Id {connectionId}: Passing message to application. Payload size: {size}."); + private static readonly Action _messageToApplication = + LoggerMessage.Define(LogLevel.Debug, new EventId(10, nameof(MessageToApplication)), "Passing message to application. Payload size: {size}."); - private static readonly Action _sendPayload = - LoggerMessage.Define(LogLevel.Debug, new EventId(11, nameof(SendPayload)), "{time}: Connection Id {connectionId}: Sending payload: {size} bytes."); + private static readonly Action _sendPayload = + LoggerMessage.Define(LogLevel.Debug, new EventId(11, nameof(SendPayload)), "Sending payload: {size} bytes."); - private static readonly Action _errorWritingFrame = - LoggerMessage.Define(LogLevel.Error, new EventId(12, nameof(ErrorWritingFrame)), "{time}: Connection Id {connectionId}: Error writing frame."); + private static readonly Action _errorWritingFrame = + LoggerMessage.Define(LogLevel.Error, new EventId(12, nameof(ErrorWritingFrame)), "Error writing frame."); - private static readonly Action _sendFailed = - LoggerMessage.Define(LogLevel.Trace, new EventId(13, nameof(SendFailed)), "{time}: Connection Id {connectionId}: Socket failed to send."); + private static readonly Action _sendFailed = + LoggerMessage.Define(LogLevel.Trace, new EventId(13, nameof(SendFailed)), "Socket failed to send."); // Category: ServerSentEventsTransport - private static readonly Action _sseWritingMessage = - LoggerMessage.Define(LogLevel.Debug, new EventId(1, nameof(SSEWritingMessage)), "{time}: Connection Id {connectionId}: Writing a {count} byte message."); + private static readonly Action _sseWritingMessage = + LoggerMessage.Define(LogLevel.Debug, new EventId(1, nameof(SSEWritingMessage)), "Writing a {count} byte message."); - public static void LongPolling204(this ILogger logger, string connectionId, string requestId) + public static void LongPolling204(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Information)) - { - _longPolling204(logger, DateTime.Now, connectionId, requestId, null); - } + _longPolling204(logger, null); } - public static void PollTimedOut(this ILogger logger, string connectionId, string requestId) + public static void PollTimedOut(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Information)) - { - _pollTimedOut(logger, DateTime.Now, connectionId, requestId, null); - } + _pollTimedOut(logger, null); } - public static void LongPollingWritingMessage(this ILogger logger, string connectionId, string requestId, int count) + public static void LongPollingWritingMessage(this ILogger logger, int count) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _longPollingWritingMessage(logger, DateTime.Now, connectionId, requestId, count, null); - } + _longPollingWritingMessage(logger, count, null); } - public static void LongPollingDisconnected(this ILogger logger, string connectionId, string requestId) + public static void LongPollingDisconnected(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _longPollingDisconnected(logger, DateTime.Now, connectionId, requestId, null); - } + _longPollingDisconnected(logger, null); } - public static void LongPollingTerminated(this ILogger logger, string connectionId, string requestId, Exception ex) + public static void LongPollingTerminated(this ILogger logger, Exception ex) { - if (logger.IsEnabled(LogLevel.Error)) - { - _longPollingTerminated(logger, DateTime.Now, connectionId, requestId, ex); - } + _longPollingTerminated(logger, ex); } public static void ConnectionDisposed(this ILogger logger, string connectionId) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _connectionDisposed(logger, DateTime.Now, connectionId, null); - } + _connectionDisposed(logger, connectionId, null); } public static void ConnectionAlreadyActive(this ILogger logger, string connectionId, string requestId) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _connectionAlreadyActive(logger, DateTime.Now, connectionId, requestId, null); - } + _connectionAlreadyActive(logger, connectionId, requestId, null); } public static void PollCanceled(this ILogger logger, string connectionId, string requestId) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _pollCanceled(logger, DateTime.Now, connectionId, requestId, null); - } + _pollCanceled(logger, connectionId, requestId, null); } - public static void EstablishedConnection(this ILogger logger, string connectionId, string requestId) + public static void EstablishedConnection(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _establishedConnection(logger, DateTime.Now, connectionId, requestId, null); - } + _establishedConnection(logger, null); } - public static void ResumingConnection(this ILogger logger, string connectionId, string requestId) + public static void ResumingConnection(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _resumingConnection(logger, DateTime.Now, connectionId, requestId, null); - } + _resumingConnection(logger, null); } - public static void ReceivedBytes(this ILogger logger, string connectionId, int count) + public static void ReceivedBytes(this ILogger logger, int count) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _receivedBytes(logger, DateTime.Now, connectionId, count, null); - } + _receivedBytes(logger, count, null); } - public static void TransportNotSupported(this ILogger logger, string connectionId, TransportType transport) + public static void TransportNotSupported(this ILogger logger, TransportType transport) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _transportNotSupported(logger, DateTime.Now, connectionId, transport, null); - } + _transportNotSupported(logger, transport, null); } - public static void CannotChangeTransport(this ILogger logger, string connectionId, TransportType transport, TransportType requestTransport) + public static void CannotChangeTransport(this ILogger logger, TransportType transport, TransportType requestTransport) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _cannotChangeTransport(logger, DateTime.Now, connectionId, transport, requestTransport, null); - } + _cannotChangeTransport(logger, transport, requestTransport, null); } - public static void PostNotAllowedForWebSockets(this ILogger logger, string connectionId) + public static void PostNotAllowedForWebSockets(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _postNotallowedForWebsockets(logger, DateTime.Now, connectionId, null); - } + _postNotallowedForWebsockets(logger, null); } - public static void NegotiationRequest(this ILogger logger, string connectionId) + public static void NegotiationRequest(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _negotiationRequest(logger, DateTime.Now, connectionId, null); - } + _negotiationRequest(logger, null); } - public static void SocketOpened(this ILogger logger, string connectionId) + public static void SocketOpened(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Information)) - { - _socketOpened(logger, DateTime.Now, connectionId, null); - } + _socketOpened(logger, null); } - public static void SocketClosed(this ILogger logger, string connectionId) + public static void SocketClosed(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Information)) - { - _socketClosed(logger, DateTime.Now, connectionId, null); - } + _socketClosed(logger, null); } - public static void ClientClosed(this ILogger logger, string connectionId, WebSocketCloseStatus? closeStatus, string closeDescription) + public static void ClientClosed(this ILogger logger, WebSocketCloseStatus? closeStatus, string closeDescription) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _clientClosed(logger, DateTime.Now, connectionId, closeStatus, closeDescription, null); - } + _clientClosed(logger, closeStatus, closeDescription, null); } - public static void WaitingForSend(this ILogger logger, string connectionId) + public static void WaitingForSend(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _waitingForSend(logger, DateTime.Now, connectionId, null); - } + _waitingForSend(logger, null); } - public static void FailedSending(this ILogger logger, string connectionId) + public static void FailedSending(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _failedSending(logger, DateTime.Now, connectionId, null); - } + _failedSending(logger, null); } - public static void FinishedSending(this ILogger logger, string connectionId) + public static void FinishedSending(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _finishedSending(logger, DateTime.Now, connectionId, null); - } + _finishedSending(logger, null); } - public static void WaitingForClose(this ILogger logger, string connectionId) + public static void WaitingForClose(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _waitingForClose(logger, DateTime.Now, connectionId, null); - } + _waitingForClose(logger, null); } - public static void CloseTimedOut(this ILogger logger, string connectionId) + public static void CloseTimedOut(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _closeTimedOut(logger, DateTime.Now, connectionId, null); - } + _closeTimedOut(logger, null); } - public static void MessageReceived(this ILogger logger, string connectionId, WebSocketMessageType type, int size, bool endOfMessage) + public static void MessageReceived(this ILogger logger, WebSocketMessageType type, int size, bool endOfMessage) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _messageReceived(logger, DateTime.Now, connectionId, type, size, endOfMessage, null); - } + _messageReceived(logger, type, size, endOfMessage, null); } - public static void MessageToApplication(this ILogger logger, string connectionId, int size) + public static void MessageToApplication(this ILogger logger, int size) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _messageToApplication(logger, DateTime.Now, connectionId, size, null); - } + _messageToApplication(logger, size, null); } - public static void SendPayload(this ILogger logger, string connectionId, int size) + public static void SendPayload(this ILogger logger, int size) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _sendPayload(logger, DateTime.Now, connectionId, size, null); - } + _sendPayload(logger, size, null); } - public static void ErrorWritingFrame(this ILogger logger, string connectionId, Exception ex) + public static void ErrorWritingFrame(this ILogger logger, Exception ex) { - if (logger.IsEnabled(LogLevel.Error)) - { - _errorWritingFrame(logger, DateTime.Now, connectionId, ex); - } + _errorWritingFrame(logger, ex); } - public static void SendFailed(this ILogger logger, string connectionId, Exception ex) + public static void SendFailed(this ILogger logger, Exception ex) { - if (logger.IsEnabled(LogLevel.Trace)) - { - _sendFailed(logger, DateTime.Now, connectionId, ex); - } + _sendFailed(logger, ex); } - public static void SSEWritingMessage(this ILogger logger, string connectionId, int count) + public static void SSEWritingMessage(this ILogger logger, int count) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _sseWritingMessage(logger, DateTime.Now, connectionId, count, null); - } + _sseWritingMessage(logger, count, null); } } } diff --git a/src/Microsoft.AspNetCore.Sockets.Http/Internal/Transports/LongPollingTransport.cs b/src/Microsoft.AspNetCore.Sockets.Http/Internal/Transports/LongPollingTransport.cs index 4992489211..893e596d78 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/Internal/Transports/LongPollingTransport.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/Internal/Transports/LongPollingTransport.cs @@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Sockets.Internal.Transports if (!await _application.WaitToReadAsync(token)) { await _application.Completion; - _logger.LongPolling204(_connectionId, context.TraceIdentifier); + _logger.LongPolling204(); context.Response.ContentType = "text/plain"; context.Response.StatusCode = StatusCodes.Status204NoContent; return; @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Sockets.Internal.Transports contentLength += buffer.Length; buffers.Add(buffer); - _logger.LongPollingWritingMessage(_connectionId, context.TraceIdentifier, buffer.Length); + _logger.LongPollingWritingMessage(buffer.Length); } context.Response.ContentLength = contentLength; @@ -72,12 +72,12 @@ namespace Microsoft.AspNetCore.Sockets.Internal.Transports { // Don't count this as cancellation, this is normal as the poll can end due to the browser closing. // The background thread will eventually dispose this connection if it's inactive - _logger.LongPollingDisconnected(_connectionId, context.TraceIdentifier); + _logger.LongPollingDisconnected(); } // Case 2 else if (_timeoutToken.IsCancellationRequested) { - _logger.PollTimedOut(_connectionId, context.TraceIdentifier); + _logger.PollTimedOut(); context.Response.ContentLength = 0; context.Response.ContentType = "text/plain"; @@ -86,14 +86,14 @@ namespace Microsoft.AspNetCore.Sockets.Internal.Transports else { // Case 3 - _logger.LongPolling204(_connectionId, context.TraceIdentifier); + _logger.LongPolling204(); context.Response.ContentType = "text/plain"; context.Response.StatusCode = StatusCodes.Status204NoContent; } } catch (Exception ex) { - _logger.LongPollingTerminated(_connectionId, context.TraceIdentifier, ex); + _logger.LongPollingTerminated(ex); throw; } } diff --git a/src/Microsoft.AspNetCore.Sockets.Http/Internal/Transports/ServerSentEventsTransport.cs b/src/Microsoft.AspNetCore.Sockets.Http/Internal/Transports/ServerSentEventsTransport.cs index 19bda2e390..2596446400 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/Internal/Transports/ServerSentEventsTransport.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/Internal/Transports/ServerSentEventsTransport.cs @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Sockets.Internal.Transports var ms = new MemoryStream(); while (_application.TryRead(out var buffer)) { - _logger.SSEWritingMessage(_connectionId, buffer.Length); + _logger.SSEWritingMessage(buffer.Length); ServerSentEventsMessageFormatter.WriteMessage(buffer, ms); } diff --git a/src/Microsoft.AspNetCore.Sockets.Http/Internal/Transports/WebSocketsTransport.cs b/src/Microsoft.AspNetCore.Sockets.Http/Internal/Transports/WebSocketsTransport.cs index 5d6b551066..e3ec5aa6f0 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/Internal/Transports/WebSocketsTransport.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/Internal/Transports/WebSocketsTransport.cs @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Sockets.Internal.Transports using (var ws = await context.WebSockets.AcceptWebSocketAsync(_options.SubProtocol)) { - _logger.SocketOpened(_connection.ConnectionId); + _logger.SocketOpened(); try { @@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.Sockets.Internal.Transports } finally { - _logger.SocketClosed(_connection.ConnectionId); + _logger.SocketClosed(); } } } @@ -78,12 +78,12 @@ namespace Microsoft.AspNetCore.Sockets.Internal.Transports if (trigger == receiving) { task = sending; - _logger.WaitingForSend(_connection.ConnectionId); + _logger.WaitingForSend(); } else { task = receiving; - _logger.WaitingForClose(_connection.ConnectionId); + _logger.WaitingForClose(); } // We're done writing @@ -95,7 +95,7 @@ namespace Microsoft.AspNetCore.Sockets.Internal.Transports if (resultTask != task) { - _logger.CloseTimedOut(_connection.ConnectionId); + _logger.CloseTimedOut(); socket.Abort(); } else @@ -129,7 +129,7 @@ namespace Microsoft.AspNetCore.Sockets.Internal.Transports return receiveResult; } - _logger.MessageReceived(_connection.ConnectionId, receiveResult.MessageType, receiveResult.Count, receiveResult.EndOfMessage); + _logger.MessageReceived(receiveResult.MessageType, receiveResult.Count, receiveResult.EndOfMessage); var truncBuffer = new ArraySegment(buffer.Array, 0, receiveResult.Count); incomingMessage.Add(truncBuffer); @@ -159,7 +159,7 @@ namespace Microsoft.AspNetCore.Sockets.Internal.Transports Buffer.BlockCopy(incomingMessage[0].Array, incomingMessage[0].Offset, messageBuffer, 0, incomingMessage[0].Count); } - _logger.MessageToApplication(_connection.ConnectionId, messageBuffer.Length); + _logger.MessageToApplication(messageBuffer.Length); while (await _application.Writer.WaitToWriteAsync()) { if (_application.Writer.TryWrite(messageBuffer)) @@ -182,7 +182,7 @@ namespace Microsoft.AspNetCore.Sockets.Internal.Transports { try { - _logger.SendPayload(_connection.ConnectionId, buffer.Length); + _logger.SendPayload(buffer.Length); var webSocketMessageType = (_connection.TransferMode == TransferMode.Binary ? WebSocketMessageType.Binary @@ -196,12 +196,12 @@ namespace Microsoft.AspNetCore.Sockets.Internal.Transports catch (WebSocketException socketException) when (!WebSocketCanSend(ws)) { // this can happen when we send the CloseFrame to the client and try to write afterwards - _logger.SendFailed(_connection.ConnectionId, socketException); + _logger.SendFailed(socketException); break; } catch (Exception ex) { - _logger.ErrorWritingFrame(_connection.ConnectionId, ex); + _logger.ErrorWritingFrame(ex); break; } } diff --git a/src/Microsoft.AspNetCore.Sockets/Internal/SocketLoggerExtensions.cs b/src/Microsoft.AspNetCore.Sockets/Internal/SocketLoggerExtensions.cs index afbabccdaa..6c1a8552b0 100644 --- a/src/Microsoft.AspNetCore.Sockets/Internal/SocketLoggerExtensions.cs +++ b/src/Microsoft.AspNetCore.Sockets/Internal/SocketLoggerExtensions.cs @@ -9,81 +9,60 @@ namespace Microsoft.AspNetCore.Sockets.Internal internal static class SocketLoggerExtensions { // Category: ConnectionManager - private static readonly Action _createdNewConnection = - LoggerMessage.Define(LogLevel.Debug, new EventId(1, nameof(CreatedNewConnection)), "{time}: ConnectionId {connectionId}: New connection created."); + private static readonly Action _createdNewConnection = + LoggerMessage.Define(LogLevel.Debug, new EventId(1, nameof(CreatedNewConnection)), "New connection {connectionId} created."); - private static readonly Action _removedConnection = - LoggerMessage.Define(LogLevel.Debug, new EventId(2, nameof(RemovedConnection)), "{time}: ConnectionId {connectionId}: Removing connection from the list of connections."); + private static readonly Action _removedConnection = + LoggerMessage.Define(LogLevel.Debug, new EventId(2, nameof(RemovedConnection)), "Removing connection {connectionId} from the list of connections."); - private static readonly Action _failedDispose = - LoggerMessage.Define(LogLevel.Error, new EventId(3, nameof(FailedDispose)), "{time}: ConnectionId {connectionId}: Failed disposing connection."); + private static readonly Action _failedDispose = + LoggerMessage.Define(LogLevel.Error, new EventId(3, nameof(FailedDispose)), "Failed disposing connection {connectionId}."); - private static readonly Action _connectionReset = - LoggerMessage.Define(LogLevel.Trace, new EventId(4, nameof(ConnectionReset)), "{time}: ConnectionId {connectionId}: Connection was reset."); + private static readonly Action _connectionReset = + LoggerMessage.Define(LogLevel.Trace, new EventId(4, nameof(ConnectionReset)), "Connection {connectionId} was reset."); - private static readonly Action _connectionTimedOut = - LoggerMessage.Define(LogLevel.Trace, new EventId(5, nameof(ConnectionTimedOut)), "{time}: ConnectionId {connectionId}: Connection timed out."); + private static readonly Action _connectionTimedOut = + LoggerMessage.Define(LogLevel.Trace, new EventId(5, nameof(ConnectionTimedOut)), "Connection {connectionId} timed out."); - private static readonly Action _scanningConnections = - LoggerMessage.Define(LogLevel.Trace, new EventId(6, nameof(ScanningConnections)), "{time}: Scanning connections."); + private static readonly Action _scanningConnections = + LoggerMessage.Define(LogLevel.Trace, new EventId(6, nameof(ScanningConnections)), "Scanning connections."); - private static readonly Action _scannedConnections = - LoggerMessage.Define(LogLevel.Trace, new EventId(7, nameof(ScannedConnections)), "{time}: Scanned connections in {duration}."); + private static readonly Action _scannedConnections = + LoggerMessage.Define(LogLevel.Trace, new EventId(7, nameof(ScannedConnections)), "Scanned connections in {duration}."); public static void CreatedNewConnection(this ILogger logger, string connectionId) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _createdNewConnection(logger, DateTime.Now, connectionId, null); - } + _createdNewConnection(logger, connectionId, null); } public static void RemovedConnection(this ILogger logger, string connectionId) { - if (logger.IsEnabled(LogLevel.Debug)) - { - _removedConnection(logger, DateTime.Now, connectionId, null); - } + _removedConnection(logger, connectionId, null); } public static void FailedDispose(this ILogger logger, string connectionId, Exception exception) { - if (logger.IsEnabled(LogLevel.Error)) - { - _failedDispose(logger, DateTime.Now, connectionId, exception); - } + _failedDispose(logger, connectionId, exception); } public static void ConnectionTimedOut(this ILogger logger, string connectionId) { - if (logger.IsEnabled(LogLevel.Trace)) - { - _connectionTimedOut(logger, DateTime.Now, connectionId, null); - } + _connectionTimedOut(logger, connectionId, null); } public static void ConnectionReset(this ILogger logger, string connectionId, Exception exception) { - if (logger.IsEnabled(LogLevel.Trace)) - { - _connectionReset(logger, DateTime.Now, connectionId, exception); - } + _connectionReset(logger, connectionId, exception); } public static void ScanningConnections(this ILogger logger) { - if (logger.IsEnabled(LogLevel.Trace)) - { - _scanningConnections(logger, DateTime.Now, null); - } + _scanningConnections(logger, null); } public static void ScannedConnections(this ILogger logger, TimeSpan duration) { - if (logger.IsEnabled(LogLevel.Trace)) - { - _scannedConnections(logger, DateTime.Now, duration, null); - } + _scannedConnections(logger, duration, null); } } } diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/LongPollingTransportTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/LongPollingTransportTests.cs index e4e5e43a15..918db74227 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/LongPollingTransportTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/LongPollingTransportTests.cs @@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Client.Tests var connectionToTransport = Channel.CreateUnbounded(); var transportToConnection = Channel.CreateUnbounded(); var channelConnection = new ChannelConnection(connectionToTransport, transportToConnection); - await longPollingTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, TransferMode.Binary, connectionId: string.Empty, connection: new TestConnection()); + await longPollingTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, TransferMode.Binary, connection: new TestConnection()); transportActiveTask = longPollingTransport.Running; @@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.Client.Tests var connectionToTransport = Channel.CreateUnbounded(); var transportToConnection = Channel.CreateUnbounded(); var channelConnection = ChannelConnection.Create(connectionToTransport, transportToConnection); - await longPollingTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, TransferMode.Binary, connectionId: string.Empty, connection: new TestConnection()); + await longPollingTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, TransferMode.Binary, connection: new TestConnection()); await longPollingTransport.Running.OrTimeout(); Assert.True(transportToConnection.Reader.Completion.IsCompleted); @@ -133,7 +133,7 @@ namespace Microsoft.AspNetCore.Client.Tests var connectionToTransport = Channel.CreateUnbounded(); var transportToConnection = Channel.CreateUnbounded(); var channelConnection = new ChannelConnection(connectionToTransport, transportToConnection); - await longPollingTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, TransferMode.Binary, connectionId: string.Empty, connection: new TestConnection()); + await longPollingTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, TransferMode.Binary, connection: new TestConnection()); var data = await transportToConnection.Reader.ReadAllAsync().OrTimeout(); await longPollingTransport.Running.OrTimeout(); @@ -169,7 +169,7 @@ namespace Microsoft.AspNetCore.Client.Tests var connectionToTransport = Channel.CreateUnbounded(); var transportToConnection = Channel.CreateUnbounded(); var channelConnection = new ChannelConnection(connectionToTransport, transportToConnection); - await longPollingTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, TransferMode.Binary, connectionId: string.Empty, connection: new TestConnection()); + await longPollingTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, TransferMode.Binary, connection: new TestConnection()); var exception = await Assert.ThrowsAsync(async () => await transportToConnection.Reader.Completion.OrTimeout()); @@ -205,7 +205,7 @@ namespace Microsoft.AspNetCore.Client.Tests var connectionToTransport = Channel.CreateUnbounded(); var transportToConnection = Channel.CreateUnbounded(); var channelConnection = new ChannelConnection(connectionToTransport, transportToConnection); - await longPollingTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, TransferMode.Binary, connectionId: string.Empty, connection: new TestConnection()); + await longPollingTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, TransferMode.Binary, connection: new TestConnection()); await connectionToTransport.Writer.WriteAsync(new SendMessage()); @@ -246,7 +246,7 @@ namespace Microsoft.AspNetCore.Client.Tests var connectionToTransport = Channel.CreateUnbounded(); var transportToConnection = Channel.CreateUnbounded(); var channelConnection = new ChannelConnection(connectionToTransport, transportToConnection); - await longPollingTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, TransferMode.Binary, connectionId: string.Empty, connection: new TestConnection()); + await longPollingTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, TransferMode.Binary, connection: new TestConnection()); connectionToTransport.Writer.Complete(); @@ -297,7 +297,7 @@ namespace Microsoft.AspNetCore.Client.Tests var channelConnection = new ChannelConnection(connectionToTransport, transportToConnection); // Start the transport - await longPollingTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, TransferMode.Binary, connectionId: string.Empty, connection: new TestConnection()); + await longPollingTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, TransferMode.Binary, connection: new TestConnection()); // Wait for the transport to finish await longPollingTransport.Running.OrTimeout(); @@ -362,7 +362,7 @@ namespace Microsoft.AspNetCore.Client.Tests await connectionToTransport.Writer.WriteAsync(new SendMessage(Encoding.UTF8.GetBytes("World"), tcs2)).OrTimeout(); // Start the transport - await longPollingTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, TransferMode.Binary, connectionId: string.Empty, connection: new TestConnection()); + await longPollingTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, TransferMode.Binary, connection: new TestConnection()); connectionToTransport.Writer.Complete(); @@ -405,7 +405,7 @@ namespace Microsoft.AspNetCore.Client.Tests var channelConnection = new ChannelConnection(connectionToTransport, transportToConnection); Assert.Null(longPollingTransport.Mode); - await longPollingTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, transferMode, connectionId: string.Empty, connection: new TestConnection()); + await longPollingTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, transferMode, connection: new TestConnection()); Assert.Equal(transferMode, longPollingTransport.Mode); } finally @@ -431,7 +431,7 @@ namespace Microsoft.AspNetCore.Client.Tests { var longPollingTransport = new LongPollingTransport(httpClient); var exception = await Assert.ThrowsAsync(() => - longPollingTransport.StartAsync(new Uri("http://fakeuri.org"), null, TransferMode.Text | TransferMode.Binary, connectionId: string.Empty, connection: new TestConnection())); + longPollingTransport.StartAsync(new Uri("http://fakeuri.org"), null, TransferMode.Text | TransferMode.Binary, connection: new TestConnection())); Assert.Contains("Invalid transfer mode.", exception.Message); Assert.Equal("requestedTransferMode", exception.ParamName); @@ -469,7 +469,7 @@ namespace Microsoft.AspNetCore.Client.Tests var connectionToTransport = Channel.CreateUnbounded(); var transportToConnection = Channel.CreateUnbounded(); var channelConnection = new ChannelConnection(connectionToTransport, transportToConnection); - await longPollingTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, TransferMode.Binary, connectionId: string.Empty, connection: new TestConnection()); + await longPollingTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, TransferMode.Binary, connection: new TestConnection()); var completedTask = await Task.WhenAny(completionTcs.Task, longPollingTransport.Running).OrTimeout(); Assert.Equal(completionTcs.Task, completedTask); diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/ServerSentEventsTransportTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/ServerSentEventsTransportTests.cs index 880ae28b40..2ff0334525 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/ServerSentEventsTransportTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/ServerSentEventsTransportTests.cs @@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests var transportToConnection = Channel.CreateUnbounded(); var channelConnection = new ChannelConnection(connectionToTransport, transportToConnection); await sseTransport.StartAsync( - new Uri("http://fakeuri.org"), channelConnection, TransferMode.Text, connectionId: string.Empty, connection: Mock.Of()).OrTimeout(); + new Uri("http://fakeuri.org"), channelConnection, TransferMode.Text, connection: Mock.Of()).OrTimeout(); await eventStreamTcs.Task.OrTimeout(); await sseTransport.StopAsync().OrTimeout(); @@ -106,7 +106,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests var transportToConnection = Channel.CreateUnbounded(); var channelConnection = new ChannelConnection(connectionToTransport, transportToConnection); await sseTransport.StartAsync( - new Uri("http://fakeuri.org"), channelConnection, TransferMode.Text, connectionId: string.Empty, connection: Mock.Of()).OrTimeout(); + new Uri("http://fakeuri.org"), channelConnection, TransferMode.Text, connection: Mock.Of()).OrTimeout(); transportActiveTask = sseTransport.Running; Assert.False(transportActiveTask.IsCompleted); @@ -154,7 +154,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests var transportToConnection = Channel.CreateUnbounded(); var channelConnection = new ChannelConnection(connectionToTransport, transportToConnection); await sseTransport.StartAsync( - new Uri("http://fakeuri.org"), channelConnection, TransferMode.Text, connectionId: string.Empty, connection: Mock.Of()).OrTimeout(); + new Uri("http://fakeuri.org"), channelConnection, TransferMode.Text, connection: Mock.Of()).OrTimeout(); var exception = await Assert.ThrowsAsync(() => sseTransport.Running.OrTimeout()); Assert.Equal("Incomplete message.", exception.Message); @@ -200,7 +200,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests var channelConnection = new ChannelConnection(connectionToTransport, transportToConnection); await sseTransport.StartAsync( - new Uri("http://fakeuri.org"), channelConnection, TransferMode.Text, connectionId: string.Empty, connection: Mock.Of()).OrTimeout(); + new Uri("http://fakeuri.org"), channelConnection, TransferMode.Text, connection: Mock.Of()).OrTimeout(); await eventStreamTcs.Task; var sendTcs = new TaskCompletionSource(); @@ -247,7 +247,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests var channelConnection = new ChannelConnection(connectionToTransport, transportToConnection); await sseTransport.StartAsync( - new Uri("http://fakeuri.org"), channelConnection, TransferMode.Text, connectionId: string.Empty, connection: Mock.Of()).OrTimeout(); + new Uri("http://fakeuri.org"), channelConnection, TransferMode.Text, connection: Mock.Of()).OrTimeout(); await eventStreamTcs.Task.OrTimeout(); connectionToTransport.Writer.TryComplete(null); @@ -276,7 +276,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests var transportToConnection = Channel.CreateUnbounded(); var channelConnection = new ChannelConnection(connectionToTransport, transportToConnection); await sseTransport.StartAsync( - new Uri("http://fakeuri.org"), channelConnection, TransferMode.Text, connectionId: string.Empty, connection: Mock.Of()).OrTimeout(); + new Uri("http://fakeuri.org"), channelConnection, TransferMode.Text, connection: Mock.Of()).OrTimeout(); var message = await transportToConnection.Reader.ReadAsync().AsTask().OrTimeout(); Assert.Equal("3:abc", Encoding.ASCII.GetString(message)); @@ -306,7 +306,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests var transportToConnection = Channel.CreateUnbounded(); var channelConnection = new ChannelConnection(connectionToTransport, transportToConnection); Assert.Null(sseTransport.Mode); - await sseTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, transferMode, connectionId: string.Empty, connection: Mock.Of()).OrTimeout(); + await sseTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, transferMode, connection: Mock.Of()).OrTimeout(); Assert.Equal(TransferMode.Text, sseTransport.Mode); await sseTransport.StopAsync().OrTimeout(); } @@ -331,7 +331,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests var transportToConnection = Channel.CreateUnbounded(); var channelConnection = new ChannelConnection(connectionToTransport, transportToConnection); var exception = await Assert.ThrowsAsync(() => - sseTransport.StartAsync(new Uri("http://fakeuri.org"), null, TransferMode.Text | TransferMode.Binary, connectionId: string.Empty, connection: Mock.Of())); + sseTransport.StartAsync(new Uri("http://fakeuri.org"), null, TransferMode.Text | TransferMode.Binary, connection: Mock.Of())); Assert.Contains("Invalid transfer mode.", exception.Message); Assert.Equal("requestedTransferMode", exception.ParamName); diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestTransport.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestTransport.cs index b32808fc8b..a5ae73ecbf 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestTransport.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestTransport.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests Mode = transferMode; } - public Task StartAsync(Uri url, Channel application, TransferMode requestedTransferMode, string connectionId, IConnection connection) + public Task StartAsync(Uri url, Channel application, TransferMode requestedTransferMode, IConnection connection) { Application = application; return _startHandler(); diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/WebSocketsTransportTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/WebSocketsTransportTests.cs index 946bbbf877..0e250e26cf 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/WebSocketsTransportTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/WebSocketsTransportTests.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests var webSocketsTransport = new WebSocketsTransport(httpOptions: null, loggerFactory: loggerFactory); await webSocketsTransport.StartAsync(new Uri(_serverFixture.WebSocketsUrl + "/echo"), channelConnection, - TransferMode.Binary, connectionId: string.Empty, connection: Mock.Of()).OrTimeout(); + TransferMode.Binary, connection: Mock.Of()).OrTimeout(); await webSocketsTransport.StopAsync().OrTimeout(); await webSocketsTransport.Running.OrTimeout(); } @@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests var webSocketsTransport = new WebSocketsTransport(httpOptions: null, loggerFactory: loggerFactory); await webSocketsTransport.StartAsync(new Uri(_serverFixture.WebSocketsUrl + "/echo"), channelConnection, - TransferMode.Binary, connectionId: string.Empty, connection: Mock.Of()); + TransferMode.Binary, connection: Mock.Of()); connectionToTransport.Writer.TryComplete(); await webSocketsTransport.Running.OrTimeout(TimeSpan.FromSeconds(10)); } @@ -79,7 +79,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests var channelConnection = new ChannelConnection(connectionToTransport, transportToConnection); var webSocketsTransport = new WebSocketsTransport(httpOptions: null, loggerFactory: loggerFactory); - await webSocketsTransport.StartAsync(new Uri(_serverFixture.WebSocketsUrl + "/echo"), channelConnection, transferMode, connectionId: string.Empty, connection: Mock.Of()); + await webSocketsTransport.StartAsync(new Uri(_serverFixture.WebSocketsUrl + "/echo"), channelConnection, transferMode, connection: Mock.Of()); var sendTcs = new TaskCompletionSource(); connectionToTransport.Writer.TryWrite(new SendMessage(new byte[] { 0x42 }, sendTcs)); @@ -120,7 +120,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests Assert.Null(webSocketsTransport.Mode); await webSocketsTransport.StartAsync(new Uri(_serverFixture.WebSocketsUrl + "/echo"), channelConnection, - transferMode, connectionId: string.Empty, connection: Mock.Of()).OrTimeout(); + transferMode, connection: Mock.Of()).OrTimeout(); Assert.Equal(transferMode, webSocketsTransport.Mode); await webSocketsTransport.StopAsync().OrTimeout(); @@ -140,7 +140,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests var webSocketsTransport = new WebSocketsTransport(httpOptions: null, loggerFactory: loggerFactory); var exception = await Assert.ThrowsAsync(() => - webSocketsTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, TransferMode.Text | TransferMode.Binary, connectionId: string.Empty, connection: Mock.Of())); + webSocketsTransport.StartAsync(new Uri("http://fakeuri.org"), channelConnection, TransferMode.Text | TransferMode.Binary, connection: Mock.Of())); Assert.Contains("Invalid transfer mode.", exception.Message); Assert.Equal("requestedTransferMode", exception.ParamName);