React to Logging in DI changes
This commit is contained in:
parent
6d9f56bf4e
commit
ce280cba00
|
|
@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Sockets;
|
||||||
using Microsoft.AspNetCore.TestHost;
|
using Microsoft.AspNetCore.TestHost;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Logging.Console;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
||||||
|
|
@ -197,14 +198,18 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
||||||
_testServer.Dispose();
|
_testServer.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static LoggerFactory CreateLogger()
|
private static ILoggerFactory CreateLogger()
|
||||||
{
|
{
|
||||||
var loggerFactory = new LoggerFactory();
|
var serviceCollection = new ServiceCollection();
|
||||||
loggerFactory.AddConsole();
|
|
||||||
loggerFactory.AddFilter("Console", level => level >= (_verbose ? LogLevel.Trace : LogLevel.Error));
|
|
||||||
loggerFactory.AddDebug();
|
|
||||||
|
|
||||||
return loggerFactory;
|
serviceCollection.AddLogging(builder =>
|
||||||
|
{
|
||||||
|
builder.AddConsole();
|
||||||
|
builder.AddFilter<ConsoleLoggerProvider>(level => level >= (_verbose ? LogLevel.Trace : LogLevel.Error));
|
||||||
|
builder.AddDebug();
|
||||||
|
});
|
||||||
|
|
||||||
|
return serviceCollection.BuildServiceProvider().GetRequiredService<ILoggerFactory>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TestHub : Hub
|
public class TestHub : Hub
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
|
{
|
||||||
|
internal class ForwardingLoggerProvider : ILoggerProvider
|
||||||
|
{
|
||||||
|
private readonly ILoggerFactory _loggerFactory;
|
||||||
|
|
||||||
|
public ForwardingLoggerProvider(ILoggerFactory loggerFactory)
|
||||||
|
{
|
||||||
|
_loggerFactory = loggerFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public ILogger CreateLogger(string categoryName)
|
||||||
|
{
|
||||||
|
return _loggerFactory.CreateLogger(categoryName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
private void StartServer()
|
private void StartServer()
|
||||||
{
|
{
|
||||||
host = new WebHostBuilder()
|
host = new WebHostBuilder()
|
||||||
.UseLoggerFactory(_loggerFactory)
|
.ConfigureLogging(builder => builder.AddProvider(new ForwardingLoggerProvider(_loggerFactory)))
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.UseUrls(BaseUrl)
|
.UseUrls(BaseUrl)
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||||
|
|
@ -88,5 +88,4 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
host.Dispose();
|
host.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ using System.IO;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Logging.Console;
|
||||||
|
|
||||||
namespace WebSocketsTestApp
|
namespace WebSocketsTestApp
|
||||||
{
|
{
|
||||||
|
|
@ -21,7 +22,7 @@ namespace WebSocketsTestApp
|
||||||
.ConfigureLogging(factory =>
|
.ConfigureLogging(factory =>
|
||||||
{
|
{
|
||||||
factory.AddConsole();
|
factory.AddConsole();
|
||||||
factory.AddFilter("Console", level => level >= LogLevel.Debug);
|
factory.AddFilter<ConsoleLoggerProvider>(level => level >= LogLevel.Debug);
|
||||||
})
|
})
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue