Log connection resets as trace not error (#799)

This commit is contained in:
BrennanConroy 2017-08-30 14:57:26 -07:00 committed by GitHub
parent 5ff5c38325
commit b8d2d24b67
2 changed files with 21 additions and 0 deletions

View File

@ -5,6 +5,8 @@ using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net.WebSockets;
using System.Threading;
using System.Threading.Tasks;
using System.Threading.Tasks.Channels;
@ -178,6 +180,14 @@ namespace Microsoft.AspNetCore.Sockets
{
await connection.DisposeAsync();
}
catch (IOException ex)
{
_logger.ConnectionReset(connection.ConnectionId, ex);
}
catch (WebSocketException ex) when (ex.InnerException is IOException)
{
_logger.ConnectionReset(connection.ConnectionId, ex);
}
catch (Exception ex)
{
_logger.FailedDispose(connection.ConnectionId, ex);

View File

@ -18,6 +18,9 @@ namespace Microsoft.AspNetCore.Sockets.Internal
private static readonly Action<ILogger, DateTime, string, Exception> _failedDispose =
LoggerMessage.Define<DateTime, string>(LogLevel.Error, 2, "{time}: ConnectionId {connectionId}: Failed disposing connection.");
private static readonly Action<ILogger, DateTime, string, Exception> _connectionReset =
LoggerMessage.Define<DateTime, string>(LogLevel.Trace, 3, "{time}: ConnectionId {connectionId}: Connection was reset.");
public static void CreatedNewConnection(this ILogger logger, string connectionId)
{
if (logger.IsEnabled(LogLevel.Debug))
@ -41,5 +44,13 @@ namespace Microsoft.AspNetCore.Sockets.Internal
_failedDispose(logger, DateTime.Now, connectionId, exception);
}
}
public static void ConnectionReset(this ILogger logger, string connectionId, Exception exception)
{
if (logger.IsEnabled(LogLevel.Trace))
{
_connectionReset(logger, DateTime.Now, connectionId, exception);
}
}
}
}