Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit 7dd5884

Browse files
committed
add some logging maybe?
1 parent 95e229e commit 7dd5884

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public class HubConnection
4545

4646
public Task Closed { get; }
4747

48+
/// <summary>
49+
/// Gets or sets the server timeout interval for the connection. Changes to this value
50+
/// are ignored after <see cref="StartAsync"/> is called.
51+
/// </summary>
4852
public TimeSpan ServerTimeout { get; set; } = DefaultServerTimeout;
4953

5054
public HubConnection(IConnection connection, IHubProtocol protocol, ILoggerFactory loggerFactory)
@@ -66,12 +70,14 @@ public HubConnection(IConnection connection, IHubProtocol protocol, ILoggerFacto
6670
_logger = _loggerFactory.CreateLogger<HubConnection>();
6771
_connection.OnReceived((data, state) => ((HubConnection)state).OnDataReceivedAsync(data), this);
6872
_needKeepAlive = _connection.Features.Get<IConnectionInherentKeepAliveFeature>() == null;
69-
_timeoutTimer = new Timer(state => ((HubConnection)state).TimeoutElapsed(), this, -1, -1);
7073
Closed = _connection.Closed.ContinueWith(task =>
7174
{
7275
Shutdown(task.Exception);
7376
return task;
7477
}).Unwrap();
78+
79+
// Create the timer for timeout, but disabled by default (we enable it when started).
80+
_timeoutTimer = new Timer(state => ((HubConnection)state).TimeoutElapsed(), this, Timeout.Infinite, Timeout.Infinite);
7581
}
7682

7783
public async Task StartAsync()
@@ -95,6 +101,7 @@ private void ResetTimeoutTimer()
95101
{
96102
if (_needKeepAlive)
97103
{
104+
_logger.ResettingKeepAliveTimer();
98105
_timeoutTimer.Change(ServerTimeout, Timeout.InfiniteTimeSpan);
99106
}
100107
}

src/Microsoft.AspNetCore.SignalR.Client.Core/Internal/SignalRClientLoggerExtensions.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ internal static class SignalRClientLoggerExtensions
8585
private static readonly Action<ILogger, string, string, string, int, Exception> _preparingStreamingInvocation =
8686
LoggerMessage.Define<string, string, string, int>(LogLevel.Trace, new EventId(24, nameof(PreparingStreamingInvocation)), "Preparing streaming invocation '{invocationId}' of '{target}', with return type '{returnType}' and {argumentCount} argument(s).");
8787

88+
private static readonly Action<ILogger, Exception> _resettingKeepAliveTimer =
89+
LoggerMessage.Define(LogLevel.Trace, new EventId(25, nameof(ResettingKeepAliveTimer)), "Resetting keep-alive timer, received a message from the server");
90+
8891
// Category: Streaming and NonStreaming
8992
private static readonly Action<ILogger, string, Exception> _invocationCreated =
9093
LoggerMessage.Define<string>(LogLevel.Trace, new EventId(0, nameof(InvocationCreated)), "Invocation {invocationId} created.");
@@ -282,7 +285,12 @@ public static void StreamItemOnNonStreamInvocation(this ILogger logger, string i
282285

283286
public static void ErrorInvokingClientSideMethod(this ILogger logger, string methodName, Exception exception)
284287
{
285-
_errorInvokingClientSideMethod(logger, methodName, exception);
288+
_errorInvokingClientSideMethod(logger, methodName, exception);
289+
}
290+
291+
public static void ResettingKeepAliveTimer(this ILogger logger)
292+
{
293+
_resettingKeepAliveTimer(logger);
286294
}
287295
}
288296
}

0 commit comments

Comments
 (0)