[SignalR] Change log levels (#12742)

This commit is contained in:
Brennan 2019-08-02 10:51:23 -07:00 committed by GitHub
parent d312d797fc
commit c15f1e145f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 71 additions and 256 deletions

View File

@ -491,13 +491,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[LogLevel(LogLevel.Trace)]
public async Task StreamAsyncDoesNotStartIfTokenAlreadyCanceled(string protocolName, HttpTransportType transportType, string path)
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == DefaultHubDispatcherLoggerName &&
writeContext.EventId.Name == "FailedInvokingHubMethod";
}
var protocol = HubProtocols[protocolName];
using (StartServer<Startup>(out var server, ExpectedErrors))
using (StartServer<Startup>(out var server))
{
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try
@ -901,16 +896,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[LogLevel(LogLevel.Trace)]
public async Task CanCloseStreamMethodEarly(string protocolName, HttpTransportType transportType, string path)
{
bool ExpectedErrors(WriteContext writeContext)
{
// Writing is not allowed after writer was completed.
// Can happen since we are closing the connection while the connection could still be writing the streaming data
return writeContext.LoggerName == typeof(HubConnectionContext).FullName &&
writeContext.EventId.Name == "FailedWritingMessage";
}
var protocol = HubProtocols[protocolName];
using (StartServer<Startup>(out var server, ExpectedErrors))
using (StartServer<Startup>(out var server))
{
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try
@ -1013,14 +1000,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
public async Task ServerThrowsHubExceptionIfHubMethodCannotBeResolved(string hubProtocolName, HttpTransportType transportType, string hubPath)
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == DefaultHubDispatcherLoggerName &&
writeContext.EventId.Name == "FailedInvokingHubMethod";
}
var hubProtocol = HubProtocols[hubProtocolName];
using (StartServer<Startup>(out var server, ExpectedErrors))
using (StartServer<Startup>(out var server))
{
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try
@ -1046,14 +1027,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
public async Task ServerThrowsHubExceptionIfHubMethodCannotBeResolvedAndArgumentsPassedIn(string hubProtocolName, HttpTransportType transportType, string hubPath)
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == DefaultHubDispatcherLoggerName &&
writeContext.EventId.Name == "FailedInvokingHubMethod";
}
var hubProtocol = HubProtocols[hubProtocolName];
using (StartServer<Startup>(out var server, ExpectedErrors))
using (StartServer<Startup>(out var server))
{
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try
@ -1079,14 +1054,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(HubProtocolsList))]
public async Task ServerThrowsHubExceptionOnHubMethodArgumentCountMismatch(string hubProtocolName)
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == DefaultHubDispatcherLoggerName &&
writeContext.EventId.Name == "FailedInvokingHubMethod";
}
var hubProtocol = HubProtocols[hubProtocolName];
using (StartServer<Startup>(out var server, ExpectedErrors))
using (StartServer<Startup>(out var server))
{
var connection = CreateHubConnection(server.Url, "/default", HttpTransportType.LongPolling, hubProtocol, LoggerFactory);
try
@ -1112,14 +1081,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
public async Task ServerThrowsHubExceptionOnHubMethodArgumentTypeMismatch(string hubProtocolName, HttpTransportType transportType, string hubPath)
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == DefaultHubDispatcherLoggerName &&
writeContext.EventId.Name == "FailedInvokingHubMethod";
}
var hubProtocol = HubProtocols[hubProtocolName];
using (StartServer<Startup>(out var server, ExpectedErrors))
using (StartServer<Startup>(out var server))
{
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try
@ -1145,14 +1108,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
public async Task ServerThrowsHubExceptionIfStreamingHubMethodCannotBeResolved(string hubProtocolName, HttpTransportType transportType, string hubPath)
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == DefaultHubDispatcherLoggerName &&
writeContext.EventId.Name == "FailedInvokingHubMethod";
}
var hubProtocol = HubProtocols[hubProtocolName];
using (StartServer<Startup>(out var server, ExpectedErrors))
using (StartServer<Startup>(out var server))
{
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try
@ -1179,14 +1136,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
public async Task ServerThrowsHubExceptionOnStreamingHubMethodArgumentCountMismatch(string hubProtocolName, HttpTransportType transportType, string hubPath)
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == DefaultHubDispatcherLoggerName &&
writeContext.EventId.Name == "FailedInvokingHubMethod";
}
var hubProtocol = HubProtocols[hubProtocolName];
using (StartServer<Startup>(out var server, ExpectedErrors))
using (StartServer<Startup>(out var server))
{
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try
@ -1213,14 +1164,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
public async Task ServerThrowsHubExceptionOnStreamingHubMethodArgumentTypeMismatch(string hubProtocolName, HttpTransportType transportType, string hubPath)
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == DefaultHubDispatcherLoggerName &&
writeContext.EventId.Name == "FailedInvokingHubMethod";
}
var hubProtocol = HubProtocols[hubProtocolName];
using (StartServer<Startup>(out var server, ExpectedErrors))
using (StartServer<Startup>(out var server))
{
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try
@ -1247,14 +1192,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
public async Task ServerThrowsHubExceptionIfNonStreamMethodInvokedWithStreamAsync(string hubProtocolName, HttpTransportType transportType, string hubPath)
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == DefaultHubDispatcherLoggerName &&
writeContext.EventId.Name == "NonStreamingMethodCalledWithStream";
}
var hubProtocol = HubProtocols[hubProtocolName];
using (StartServer<Startup>(out var server, ExpectedErrors))
using (StartServer<Startup>(out var server))
{
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try
@ -1280,14 +1219,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
public async Task ServerThrowsHubExceptionIfStreamMethodInvokedWithInvoke(string hubProtocolName, HttpTransportType transportType, string hubPath)
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == DefaultHubDispatcherLoggerName &&
writeContext.EventId.Name == "StreamingMethodCalledWithInvoke";
}
var hubProtocol = HubProtocols[hubProtocolName];
using (StartServer<Startup>(out var server, ExpectedErrors))
using (StartServer<Startup>(out var server))
{
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try
@ -1313,14 +1246,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
public async Task ServerThrowsHubExceptionIfBuildingAsyncEnumeratorIsNotPossible(string hubProtocolName, HttpTransportType transportType, string hubPath)
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == DefaultHubDispatcherLoggerName &&
writeContext.EventId.Name == "InvalidReturnValueFromStreamingMethod";
}
var hubProtocol = HubProtocols[hubProtocolName];
using (StartServer<Startup>(out var server, ExpectedErrors))
using (StartServer<Startup>(out var server))
{
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try
@ -1345,16 +1272,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Fact]
public async Task RandomGenericIsNotTreatedAsStream()
{
bool ExpectedErrors(WriteContext writeContext)
{
return "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" == writeContext.LoggerName &&
"FailedInvokingHubMethod" == writeContext.EventId.Name;
}
var hubPath = HubPaths[0];
var hubProtocol = HubProtocols.First().Value;
var transportType = TransportTypes().First().Cast<HttpTransportType>().First();
using (StartServer<Startup>(out var server, ExpectedErrors))
using (StartServer<Startup>(out var server))
{
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
await connection.StartAsync().OrTimeout();

View File

@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal
LoggerMessage.Define<HttpTransportType>(LogLevel.Debug, new EventId(7, "TransportNotSupported"), "{TransportType} transport not supported by this connection handler.");
private static readonly Action<ILogger, HttpTransportType, HttpTransportType, Exception> _cannotChangeTransport =
LoggerMessage.Define<HttpTransportType, HttpTransportType>(LogLevel.Error, new EventId(8, "CannotChangeTransport"), "Cannot change transports mid-connection; currently using {TransportType}, requesting {RequestedTransport}.");
LoggerMessage.Define<HttpTransportType, HttpTransportType>(LogLevel.Debug, new EventId(8, "CannotChangeTransport"), "Cannot change transports mid-connection; currently using {TransportType}, requesting {RequestedTransport}.");
private static readonly Action<ILogger, Exception> _postNotallowedForWebsockets =
LoggerMessage.Define(LogLevel.Debug, new EventId(9, "PostNotAllowedForWebSockets"), "POST requests are not allowed for websocket connections.");

View File

@ -45,10 +45,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal.Transports
LoggerMessage.Define<long>(LogLevel.Trace, new EventId(11, "SendPayload"), "Sending payload: {Size} bytes.");
private static readonly Action<ILogger, Exception> _errorWritingFrame =
LoggerMessage.Define(LogLevel.Error, new EventId(12, "ErrorWritingFrame"), "Error writing frame.");
LoggerMessage.Define(LogLevel.Debug, new EventId(12, "ErrorWritingFrame"), "Error writing frame.");
private static readonly Action<ILogger, Exception> _sendFailed =
LoggerMessage.Define(LogLevel.Error, new EventId(13, "SendFailed"), "Socket failed to send.");
// 13, SendFailed - removed
private static readonly Action<ILogger, Exception> _closedPrematurely =
LoggerMessage.Define(LogLevel.Debug, new EventId(14, "ClosedPrematurely"), "Socket connection closed prematurely.");
@ -116,11 +115,6 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal.Transports
_errorWritingFrame(logger, ex);
}
public static void SendFailed(ILogger logger, Exception ex)
{
_sendFailed(logger, ex);
}
public static void ClosedPrematurely(ILogger logger, Exception ex)
{
_closedPrematurely(logger, ex);

View File

@ -593,7 +593,7 @@ namespace Microsoft.AspNetCore.SignalR
{
// Category: HubConnectionContext
private static readonly Action<ILogger, string, Exception> _handshakeComplete =
LoggerMessage.Define<string>(LogLevel.Information, new EventId(1, "HandshakeComplete"), "Completed connection handshake. Using HubProtocol '{Protocol}'.");
LoggerMessage.Define<string>(LogLevel.Debug, new EventId(1, "HandshakeComplete"), "Completed connection handshake. Using HubProtocol '{Protocol}'.");
private static readonly Action<ILogger, Exception> _handshakeCanceled =
LoggerMessage.Define(LogLevel.Debug, new EventId(2, "HandshakeCanceled"), "Handshake was canceled.");
@ -605,13 +605,13 @@ namespace Microsoft.AspNetCore.SignalR
LoggerMessage.Define(LogLevel.Debug, new EventId(4, "TransportBufferFull"), "Unable to send Ping message to client, the transport buffer is full.");
private static readonly Action<ILogger, Exception> _handshakeFailed =
LoggerMessage.Define(LogLevel.Error, new EventId(5, "HandshakeFailed"), "Failed connection handshake.");
LoggerMessage.Define(LogLevel.Debug, new EventId(5, "HandshakeFailed"), "Failed connection handshake.");
private static readonly Action<ILogger, Exception> _failedWritingMessage =
LoggerMessage.Define(LogLevel.Error, new EventId(6, "FailedWritingMessage"), "Failed writing message. Aborting connection.");
LoggerMessage.Define(LogLevel.Debug, new EventId(6, "FailedWritingMessage"), "Failed writing message. Aborting connection.");
private static readonly Action<ILogger, string, int, Exception> _protocolVersionFailed =
LoggerMessage.Define<string, int>(LogLevel.Warning, new EventId(7, "ProtocolVersionFailed"), "Server does not support version {Version} of the {Protocol} protocol.");
LoggerMessage.Define<string, int>(LogLevel.Debug, new EventId(7, "ProtocolVersionFailed"), "Server does not support version {Version} of the {Protocol} protocol.");
private static readonly Action<ILogger, Exception> _abortFailed =
LoggerMessage.Define(LogLevel.Trace, new EventId(8, "AbortFailed"), "Abort callback failed.");

View File

@ -287,7 +287,7 @@ namespace Microsoft.AspNetCore.SignalR
LoggerMessage.Define<string>(LogLevel.Error, new EventId(1, "ErrorDispatchingHubEvent"), "Error when dispatching '{HubMethod}' on hub.");
private static readonly Action<ILogger, Exception> _errorProcessingRequest =
LoggerMessage.Define(LogLevel.Error, new EventId(2, "ErrorProcessingRequest"), "Error when processing requests.");
LoggerMessage.Define(LogLevel.Debug, new EventId(2, "ErrorProcessingRequest"), "Error when processing requests.");
private static readonly Action<ILogger, Exception> _abortFailed =
LoggerMessage.Define(LogLevel.Trace, new EventId(3, "AbortFailed"), "Abort callback failed.");

View File

@ -16,13 +16,12 @@ namespace Microsoft.AspNetCore.SignalR.Internal
LoggerMessage.Define<InvocationMessage>(LogLevel.Debug, new EventId(1, "ReceivedHubInvocation"), "Received hub invocation: {InvocationMessage}.");
private static readonly Action<ILogger, string, Exception> _unsupportedMessageReceived =
LoggerMessage.Define<string>(LogLevel.Error, new EventId(2, "UnsupportedMessageReceived"), "Received unsupported message of type '{MessageType}'.");
LoggerMessage.Define<string>(LogLevel.Debug, new EventId(2, "UnsupportedMessageReceived"), "Received unsupported message of type '{MessageType}'.");
private static readonly Action<ILogger, string, Exception> _unknownHubMethod =
LoggerMessage.Define<string>(LogLevel.Error, new EventId(3, "UnknownHubMethod"), "Unknown hub method '{HubMethod}'.");
LoggerMessage.Define<string>(LogLevel.Debug, new EventId(3, "UnknownHubMethod"), "Unknown hub method '{HubMethod}'.");
private static readonly Action<ILogger, Exception> _outboundChannelClosed =
LoggerMessage.Define(LogLevel.Warning, new EventId(4, "OutboundChannelClosed"), "Outbound channel was closed while trying to write hub message.");
// 4, OutboundChannelClosed - removed
private static readonly Action<ILogger, string, Exception> _hubMethodNotAuthorized =
LoggerMessage.Define<string>(LogLevel.Debug, new EventId(5, "HubMethodNotAuthorized"), "Failed to invoke '{HubMethod}' because user is unauthorized.");
@ -49,13 +48,13 @@ namespace Microsoft.AspNetCore.SignalR.Internal
LoggerMessage.Define<StreamInvocationMessage>(LogLevel.Debug, new EventId(12, "ReceivedStreamHubInvocation"), "Received stream hub invocation: {InvocationMessage}.");
private static readonly Action<ILogger, HubMethodInvocationMessage, Exception> _streamingMethodCalledWithInvoke =
LoggerMessage.Define<HubMethodInvocationMessage>(LogLevel.Error, new EventId(13, "StreamingMethodCalledWithInvoke"), "A streaming method was invoked with a non-streaming invocation : {InvocationMessage}.");
LoggerMessage.Define<HubMethodInvocationMessage>(LogLevel.Debug, new EventId(13, "StreamingMethodCalledWithInvoke"), "A streaming method was invoked with a non-streaming invocation : {InvocationMessage}.");
private static readonly Action<ILogger, HubMethodInvocationMessage, Exception> _nonStreamingMethodCalledWithStream =
LoggerMessage.Define<HubMethodInvocationMessage>(LogLevel.Error, new EventId(14, "NonStreamingMethodCalledWithStream"), "A non-streaming method was invoked with a streaming invocation : {InvocationMessage}.");
LoggerMessage.Define<HubMethodInvocationMessage>(LogLevel.Debug, new EventId(14, "NonStreamingMethodCalledWithStream"), "A non-streaming method was invoked with a streaming invocation : {InvocationMessage}.");
private static readonly Action<ILogger, string, Exception> _invalidReturnValueFromStreamingMethod =
LoggerMessage.Define<string>(LogLevel.Error, new EventId(15, "InvalidReturnValueFromStreamingMethod"), "A streaming method returned a value that cannot be used to build enumerator {HubMethod}.");
LoggerMessage.Define<string>(LogLevel.Debug, new EventId(15, "InvalidReturnValueFromStreamingMethod"), "A streaming method returned a value that cannot be used to build enumerator {HubMethod}.");
private static readonly Action<ILogger, string, Exception> _receivedStreamItem =
LoggerMessage.Define<string>(LogLevel.Trace, new EventId(16, "ReceivedStreamItem"), "Received item for stream '{StreamId}'.");
@ -67,7 +66,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal
LoggerMessage.Define<string>(LogLevel.Trace, new EventId(18, "CompletingStream"), "Stream '{StreamId}' has been completed by client.");
private static readonly Action<ILogger, string, string, Exception> _closingStreamWithBindingError =
LoggerMessage.Define<string, string>(LogLevel.Warning, new EventId(19, "ClosingStreamWithBindingError"), "Stream '{StreamId}' closed with error '{Error}'.");
LoggerMessage.Define<string, string>(LogLevel.Debug, new EventId(19, "ClosingStreamWithBindingError"), "Stream '{StreamId}' closed with error '{Error}'.");
private static readonly Action<ILogger, Exception> _unexpectedStreamCompletion =
LoggerMessage.Define(LogLevel.Debug, new EventId(20, "UnexpectedStreamCompletion"), "StreamCompletionMessage received unexpectedly.");
@ -75,6 +74,9 @@ namespace Microsoft.AspNetCore.SignalR.Internal
private static readonly Action<ILogger, Exception> _unexpectedStreamItem =
LoggerMessage.Define(LogLevel.Debug, new EventId(21, "UnexpectedStreamItem"), "StreamItemMessage received unexpectedly.");
private static readonly Action<ILogger, string, Exception> _invalidHubParameters =
LoggerMessage.Define<string>(LogLevel.Debug, new EventId(22, "InvalidHubParameters"), "Parameters to hub method '{HubMethod}' are incorrect.");
public static void ReceivedHubInvocation(ILogger logger, InvocationMessage invocationMessage)
{
_receivedHubInvocation(logger, invocationMessage, null);
@ -90,11 +92,6 @@ namespace Microsoft.AspNetCore.SignalR.Internal
_unknownHubMethod(logger, hubMethod, null);
}
public static void OutboundChannelClosed(ILogger logger)
{
_outboundChannelClosed(logger, null);
}
public static void HubMethodNotAuthorized(ILogger logger, string hubMethod)
{
_hubMethodNotAuthorized(logger, hubMethod, null);
@ -184,6 +181,11 @@ namespace Microsoft.AspNetCore.SignalR.Internal
{
_unexpectedStreamItem(logger, null);
}
public static void InvalidHubParameters(ILogger logger, string hubMethod, Exception exception)
{
_invalidHubParameters(logger, hubMethod, exception);
}
}
}
}

View File

@ -157,7 +157,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal
private Task ProcessInvocationBindingFailure(HubConnectionContext connection, InvocationBindingFailureMessage bindingFailureMessage)
{
Log.FailedInvokingHubMethod(_logger, bindingFailureMessage.Target, bindingFailureMessage.BindingFailure.SourceException);
Log.InvalidHubParameters(_logger, bindingFailureMessage.Target, bindingFailureMessage.BindingFailure.SourceException);
var errorMessage = ErrorMessageHelper.BuildErrorMessage($"Failed to invoke '{bindingFailureMessage.Target}' due to an error on the server.",
bindingFailureMessage.BindingFailure.SourceException, _enableDetailedErrors);
@ -243,7 +243,11 @@ namespace Microsoft.AspNetCore.SignalR.Internal
var serverStreamLength = descriptor.StreamingParameters?.Count ?? 0;
if (clientStreamLength != serverStreamLength)
{
throw new HubException($"Client sent {clientStreamLength} stream(s), Hub method expects {serverStreamLength}.");
var ex = new HubException($"Client sent {clientStreamLength} stream(s), Hub method expects {serverStreamLength}.");
Log.InvalidHubParameters(_logger, hubMethodInvocationMessage.Target, ex);
await SendInvocationError(hubMethodInvocationMessage.InvocationId, connection,
ErrorMessageHelper.BuildErrorMessage($"An unexpected error occurred invoking '{hubMethodInvocationMessage.Target}' on the server.", ex, _enableDetailedErrors));
return;
}
InitializeHub(hub, connection);

View File

@ -163,13 +163,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[Fact]
public async Task MissingHandshakeAndMessageSentFromHubConnectionCanBeDisposedCleanly()
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == typeof(HubConnectionContext).FullName &&
writeContext.EventId.Name == "HandshakeFailed";
}
using (StartVerifiableLog(ExpectedErrors))
using (StartVerifiableLog())
{
var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(null, LoggerFactory);
var connectionHandler = serviceProvider.GetService<HubConnectionHandler<SimpleHub>>();
@ -251,13 +245,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[Fact]
public async Task HandshakeFailureFromUnknownProtocolSendsResponseWithError()
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == typeof(HubConnectionContext).FullName &&
writeContext.EventId.Name == "HandshakeFailed";
}
using (StartVerifiableLog(ExpectedErrors))
using (StartVerifiableLog())
{
var hubProtocolMock = new Mock<IHubProtocol>();
hubProtocolMock.Setup(m => m.Name).Returns("CustomProtocol");
@ -281,13 +269,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[Fact]
public async Task HandshakeFailureFromUnsupportedFormatSendsResponseWithError()
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == typeof(HubConnectionContext).FullName &&
writeContext.EventId.Name == "HandshakeFailed";
}
using (StartVerifiableLog(ExpectedErrors))
using (StartVerifiableLog())
{
var hubProtocolMock = new Mock<IHubProtocol>();
hubProtocolMock.Setup(m => m.Name).Returns("CustomProtocol");
@ -460,19 +442,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests
{
var payload = Encoding.UTF8.GetBytes("{\"type\":1, \"invocationId\":\"1\", \"target\": \"Echo\", \"arguments\":[\"hello\"]}\u001e");
var maximumMessageSize = payload.Length - 10;
InvalidDataException exception = null;
bool ExpectedErrors(WriteContext writeContext)
{
if (writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.HubConnectionHandler" && (writeContext.Exception is InvalidDataException ide))
{
exception = ide;
return true;
}
return false;
}
using (StartVerifiableLog(ExpectedErrors))
using (StartVerifiableLog())
{
var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(typeof(HubT), LoggerFactory,
services => services.AddSignalR().AddHubOptions<HubT>(o => o.MaximumReceiveMessageSize = maximumMessageSize));
@ -489,8 +460,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests
}
}
Assert.NotNull(exception);
Assert.Equal(exception.Message, $"The maximum message size of {maximumMessageSize}B was exceeded. The message size can be configured in AddHubOptions.");
var exceptionLog = TestSink.Writes.Where(w => string.Equals(w.LoggerName, "Microsoft.AspNetCore.SignalR.HubConnectionHandler") &&
(w.Exception is InvalidDataException ide));
Assert.Single(exceptionLog);
Assert.Equal(exceptionLog.First().Exception.Message, $"The maximum message size of {maximumMessageSize}B was exceeded. The message size can be configured in AddHubOptions.");
}
[Fact]
@ -498,19 +471,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests
{
var payload = Encoding.UTF8.GetBytes("{\"type\":1, \"invocationId\":\"1\", \"target\": \"Echo\", \"arguments\":[\"hello\"]}\u001e");
var maximumMessageSize = payload.Length - 10;
InvalidDataException exception = null;
bool ExpectedErrors(WriteContext writeContext)
{
if (writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.HubConnectionHandler" && (writeContext.Exception is InvalidDataException ide))
{
exception = ide;
return true;
}
return false;
}
using (StartVerifiableLog(ExpectedErrors))
using (StartVerifiableLog())
{
var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(typeof(HubT), LoggerFactory,
services => services.AddSignalR().AddHubOptions<HubT>(o => o.MaximumReceiveMessageSize = maximumMessageSize));
@ -528,8 +490,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests
}
}
Assert.NotNull(exception);
Assert.Equal(exception.Message, $"The maximum message size of {maximumMessageSize}B was exceeded. The message size can be configured in AddHubOptions.");
var exceptionLog = TestSink.Writes.Where(w => string.Equals(w.LoggerName, "Microsoft.AspNetCore.SignalR.HubConnectionHandler") &&
(w.Exception is InvalidDataException ide));
Assert.Single(exceptionLog);
Assert.Equal(exceptionLog.First().Exception.Message, $"The maximum message size of {maximumMessageSize}B was exceeded. The message size can be configured in AddHubOptions.");
}
[Fact]
@ -542,19 +506,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
// Between the first and the second payload so we'll end up slicing with some remaining in the slice for
// the next message
var maximumMessageSize = payload1.Length + 1;
InvalidDataException exception = null;
bool ExpectedErrors(WriteContext writeContext)
{
if (writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.HubConnectionHandler" && (writeContext.Exception is InvalidDataException ide))
{
exception = ide;
return true;
}
return false;
}
using (StartVerifiableLog(ExpectedErrors))
using (StartVerifiableLog())
{
var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(typeof(HubT), LoggerFactory,
services => services.AddSignalR().AddHubOptions<HubT>(o => o.MaximumReceiveMessageSize = maximumMessageSize));
@ -589,8 +541,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests
}
}
Assert.NotNull(exception);
Assert.Equal(exception.Message, $"The maximum message size of {maximumMessageSize}B was exceeded. The message size can be configured in AddHubOptions.");
var exceptionLog = TestSink.Writes.Where(w => string.Equals(w.LoggerName, "Microsoft.AspNetCore.SignalR.HubConnectionHandler") &&
(w.Exception is InvalidDataException ide));
Assert.Single(exceptionLog);
Assert.Equal(exceptionLog.First().Exception.Message, $"The maximum message size of {maximumMessageSize}B was exceeded. The message size can be configured in AddHubOptions.");
}
[Fact]
@ -668,13 +622,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[Fact]
public async Task ConnectionClosesOnServerWithPartialHandshakeMessageAndCompletedPipe()
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == typeof(HubConnectionContext).FullName &&
writeContext.EventId.Name == "HandshakeFailed";
}
using (StartVerifiableLog(ExpectedErrors))
using (StartVerifiableLog())
{
var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(typeof(HubT), loggerFactory: LoggerFactory);
@ -1170,13 +1118,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[Fact]
public async Task CannotCallOverriddenBaseHubMethod()
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" &&
writeContext.EventId.Name == "FailedInvokingHubMethod";
}
using (StartVerifiableLog(ExpectedErrors))
using (StartVerifiableLog())
{
var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(null, LoggerFactory);
@ -1220,13 +1162,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[Fact]
public async Task CannotCallStaticHubMethods()
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" &&
writeContext.EventId.Name == "FailedInvokingHubMethod";
}
using (StartVerifiableLog(ExpectedErrors))
using (StartVerifiableLog())
{
var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(null, LoggerFactory);
@ -1251,13 +1187,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[Fact]
public async Task CannotCallObjectMethodsOnHub()
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" &&
writeContext.EventId.Name == "FailedInvokingHubMethod";
}
using (StartVerifiableLog(ExpectedErrors))
using (StartVerifiableLog())
{
var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(null, LoggerFactory);
@ -1290,13 +1220,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[Fact]
public async Task CannotCallDisposeMethodOnHub()
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" &&
writeContext.EventId.Name == "FailedInvokingHubMethod";
}
using (StartVerifiableLog(ExpectedErrors))
using (StartVerifiableLog())
{
var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(null, LoggerFactory);
@ -2995,13 +2919,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[Fact]
public async Task ServerSendsCloseWithErrorWhenConnectionClosedWithPartialMessage()
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.HubConnectionHandler" &&
writeContext.EventId.Name == "ErrorProcessingRequest";
}
using (StartVerifiableLog(ExpectedErrors))
using (StartVerifiableLog())
{
var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(services =>
{
@ -3154,14 +3072,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[Fact(Skip = "Cyclic parsing is not supported yet")]
public async Task ConnectionAbortedIfSendFailsWithProtocolError()
{
bool ExpectedErrors(WriteContext writeContext)
{
// Self referencing class will cause write failure
return writeContext.LoggerName == typeof(HubConnectionContext).FullName &&
writeContext.EventId.Name == "FailedWritingMessage";
}
using (StartVerifiableLog(ExpectedErrors))
using (StartVerifiableLog())
{
var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(services =>
{
@ -3333,13 +3244,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[Fact]
public async Task UploadStreamWithTooManyStreamsFails()
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" &&
writeContext.EventId.Name == "FailedInvokingHubMethod";
}
using (StartVerifiableLog(ExpectedErrors))
using (StartVerifiableLog())
{
var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(loggerFactory: LoggerFactory);
var connectionHandler = serviceProvider.GetService<HubConnectionHandler<MethodHub>>();
@ -3358,13 +3263,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[Fact]
public async Task UploadStreamWithTooFewStreamsFails()
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" &&
writeContext.EventId.Name == "FailedInvokingHubMethod";
}
using (StartVerifiableLog(ExpectedErrors))
using (StartVerifiableLog())
{
var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(loggerFactory: LoggerFactory);
var connectionHandler = serviceProvider.GetService<HubConnectionHandler<MethodHub>>();
@ -3570,13 +3469,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[Fact]
public async Task InvokeHubMethodCannotAcceptCancellationTokenAsArgument()
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" &&
writeContext.EventId.Name == "FailedInvokingHubMethod";
}
using (StartVerifiableLog(ExpectedErrors))
using (StartVerifiableLog())
{
var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(null, LoggerFactory);
var connectionHandler = serviceProvider.GetService<HubConnectionHandler<MethodHub>>();

View File

@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Internal
LoggerMessage.Define(LogLevel.Error, new EventId(9, "ConnectionFailed"), "Connection to Redis failed.");
private static readonly Action<ILogger, Exception> _failedWritingMessage =
LoggerMessage.Define(LogLevel.Warning, new EventId(10, "FailedWritingMessage"), "Failed writing message.");
LoggerMessage.Define(LogLevel.Debug, new EventId(10, "FailedWritingMessage"), "Failed writing message.");
private static readonly Action<ILogger, Exception> _internalMessageFailed =
LoggerMessage.Define(LogLevel.Warning, new EventId(11, "InternalMessageFailed"), "Error processing message for internal server message.");