diff --git a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs index 922c80a7eb..8f889b95af 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs @@ -12,6 +12,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Http.Connections; using Microsoft.AspNetCore.Http.Connections.Client; +using Microsoft.AspNetCore.SignalR.Internal; using Microsoft.AspNetCore.SignalR.Protocol; using Microsoft.AspNetCore.SignalR.Tests; using Microsoft.AspNetCore.Testing.xunit; @@ -437,7 +438,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests { bool ExpectedErrors(WriteContext writeContext) { - return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Tests.ServerLogScope" && + return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" && writeContext.EventId.Name == "FailedInvokingHubMethod"; } @@ -471,7 +472,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests { bool ExpectedErrors(WriteContext writeContext) { - return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Tests.ServerLogScope" && + return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" && writeContext.EventId.Name == "UnknownHubMethod"; } @@ -570,7 +571,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests { bool ExpectedErrors(WriteContext writeContext) { - return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Tests.ServerLogScope" && + return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" && writeContext.EventId.Name == "UnknownHubMethod"; } @@ -639,7 +640,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests { bool ExpectedErrors(WriteContext writeContext) { - return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Tests.ServerLogScope" && + return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" && writeContext.EventId.Name == "FailedInvokingHubMethod"; } @@ -673,7 +674,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests { bool ExpectedErrors(WriteContext writeContext) { - return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Tests.ServerLogScope" && + return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" && writeContext.EventId.Name == "NonStreamingMethodCalledWithStream"; } @@ -706,7 +707,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests { bool ExpectedErrors(WriteContext writeContext) { - return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Tests.ServerLogScope" && + return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" && writeContext.EventId.Name == "StreamingMethodCalledWithInvoke"; } @@ -739,7 +740,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests { bool ExpectedErrors(WriteContext writeContext) { - return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Tests.ServerLogScope" && + return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" && writeContext.EventId.Name == "InvalidReturnValueFromStreamingMethod"; } diff --git a/test/Microsoft.AspNetCore.SignalR.Tests.Utils/ServerLogScope.cs b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/ServerLogScope.cs index 5ff8ad4c52..ead19e80a3 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests.Utils/ServerLogScope.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/ServerLogScope.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Concurrent; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.SignalR.Tests @@ -9,21 +10,24 @@ namespace Microsoft.AspNetCore.SignalR.Tests public class ServerLogScope : IDisposable { private readonly ServerFixture _serverFixture; + private readonly ILoggerFactory _loggerFactory; private readonly IDisposable _wrappedDisposable; - private readonly ILogger _logger; + private readonly ConcurrentDictionary _loggers; public ServerLogScope(ServerFixture serverFixture, ILoggerFactory loggerFactory, IDisposable wrappedDisposable) { _serverFixture = serverFixture; + _loggerFactory = loggerFactory; _wrappedDisposable = wrappedDisposable; - _logger = loggerFactory.CreateLogger(typeof(ServerLogScope)); + _loggers = new ConcurrentDictionary(StringComparer.Ordinal); _serverFixture.ServerLogged += ServerFixtureOnServerLogged; } private void ServerFixtureOnServerLogged(LogRecord logRecord) { - _logger.Log(logRecord.Write.LogLevel, logRecord.Write.EventId, logRecord.Write.State, logRecord.Write.Exception, logRecord.Write.Formatter); + var logger = _loggers.GetOrAdd(logRecord.Write.LoggerName, loggerName => _loggerFactory.CreateLogger(loggerName)); + logger.Log(logRecord.Write.LogLevel, logRecord.Write.EventId, logRecord.Write.State, logRecord.Write.Exception, logRecord.Write.Formatter); } public void Dispose()