Improvements!
This commit is contained in:
parent
5b188018f0
commit
5a64429fd5
|
|
@ -12,6 +12,7 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Connections;
|
using Microsoft.AspNetCore.Connections;
|
||||||
using Microsoft.AspNetCore.Http.Connections;
|
using Microsoft.AspNetCore.Http.Connections;
|
||||||
using Microsoft.AspNetCore.Http.Connections.Client;
|
using Microsoft.AspNetCore.Http.Connections.Client;
|
||||||
|
using Microsoft.AspNetCore.SignalR.Internal;
|
||||||
using Microsoft.AspNetCore.SignalR.Protocol;
|
using Microsoft.AspNetCore.SignalR.Protocol;
|
||||||
using Microsoft.AspNetCore.SignalR.Tests;
|
using Microsoft.AspNetCore.SignalR.Tests;
|
||||||
using Microsoft.AspNetCore.Testing.xunit;
|
using Microsoft.AspNetCore.Testing.xunit;
|
||||||
|
|
@ -437,7 +438,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
||||||
{
|
{
|
||||||
bool ExpectedErrors(WriteContext writeContext)
|
bool ExpectedErrors(WriteContext writeContext)
|
||||||
{
|
{
|
||||||
return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Tests.ServerLogScope" &&
|
return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" &&
|
||||||
writeContext.EventId.Name == "FailedInvokingHubMethod";
|
writeContext.EventId.Name == "FailedInvokingHubMethod";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -471,7 +472,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
||||||
{
|
{
|
||||||
bool ExpectedErrors(WriteContext writeContext)
|
bool ExpectedErrors(WriteContext writeContext)
|
||||||
{
|
{
|
||||||
return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Tests.ServerLogScope" &&
|
return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" &&
|
||||||
writeContext.EventId.Name == "UnknownHubMethod";
|
writeContext.EventId.Name == "UnknownHubMethod";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -570,7 +571,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
||||||
{
|
{
|
||||||
bool ExpectedErrors(WriteContext writeContext)
|
bool ExpectedErrors(WriteContext writeContext)
|
||||||
{
|
{
|
||||||
return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Tests.ServerLogScope" &&
|
return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" &&
|
||||||
writeContext.EventId.Name == "UnknownHubMethod";
|
writeContext.EventId.Name == "UnknownHubMethod";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -639,7 +640,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
||||||
{
|
{
|
||||||
bool ExpectedErrors(WriteContext writeContext)
|
bool ExpectedErrors(WriteContext writeContext)
|
||||||
{
|
{
|
||||||
return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Tests.ServerLogScope" &&
|
return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" &&
|
||||||
writeContext.EventId.Name == "FailedInvokingHubMethod";
|
writeContext.EventId.Name == "FailedInvokingHubMethod";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -673,7 +674,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
||||||
{
|
{
|
||||||
bool ExpectedErrors(WriteContext writeContext)
|
bool ExpectedErrors(WriteContext writeContext)
|
||||||
{
|
{
|
||||||
return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Tests.ServerLogScope" &&
|
return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" &&
|
||||||
writeContext.EventId.Name == "NonStreamingMethodCalledWithStream";
|
writeContext.EventId.Name == "NonStreamingMethodCalledWithStream";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -706,7 +707,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
||||||
{
|
{
|
||||||
bool ExpectedErrors(WriteContext writeContext)
|
bool ExpectedErrors(WriteContext writeContext)
|
||||||
{
|
{
|
||||||
return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Tests.ServerLogScope" &&
|
return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" &&
|
||||||
writeContext.EventId.Name == "StreamingMethodCalledWithInvoke";
|
writeContext.EventId.Name == "StreamingMethodCalledWithInvoke";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -739,7 +740,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
||||||
{
|
{
|
||||||
bool ExpectedErrors(WriteContext writeContext)
|
bool ExpectedErrors(WriteContext writeContext)
|
||||||
{
|
{
|
||||||
return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Tests.ServerLogScope" &&
|
return writeContext.LoggerName == "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher" &&
|
||||||
writeContext.EventId.Name == "InvalidReturnValueFromStreamingMethod";
|
writeContext.EventId.Name == "InvalidReturnValueFromStreamingMethod";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.SignalR.Tests
|
namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
|
|
@ -9,21 +10,24 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
public class ServerLogScope : IDisposable
|
public class ServerLogScope : IDisposable
|
||||||
{
|
{
|
||||||
private readonly ServerFixture _serverFixture;
|
private readonly ServerFixture _serverFixture;
|
||||||
|
private readonly ILoggerFactory _loggerFactory;
|
||||||
private readonly IDisposable _wrappedDisposable;
|
private readonly IDisposable _wrappedDisposable;
|
||||||
private readonly ILogger _logger;
|
private readonly ConcurrentDictionary<string, ILogger> _loggers;
|
||||||
|
|
||||||
public ServerLogScope(ServerFixture serverFixture, ILoggerFactory loggerFactory, IDisposable wrappedDisposable)
|
public ServerLogScope(ServerFixture serverFixture, ILoggerFactory loggerFactory, IDisposable wrappedDisposable)
|
||||||
{
|
{
|
||||||
_serverFixture = serverFixture;
|
_serverFixture = serverFixture;
|
||||||
|
_loggerFactory = loggerFactory;
|
||||||
_wrappedDisposable = wrappedDisposable;
|
_wrappedDisposable = wrappedDisposable;
|
||||||
_logger = loggerFactory.CreateLogger(typeof(ServerLogScope));
|
_loggers = new ConcurrentDictionary<string, ILogger>(StringComparer.Ordinal);
|
||||||
|
|
||||||
_serverFixture.ServerLogged += ServerFixtureOnServerLogged;
|
_serverFixture.ServerLogged += ServerFixtureOnServerLogged;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ServerFixtureOnServerLogged(LogRecord logRecord)
|
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()
|
public void Dispose()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue