diff --git a/SignalR.sln b/SignalR.sln index abdb147a91..cb06185f7b 100644 --- a/SignalR.sln +++ b/SignalR.sln @@ -65,7 +65,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{6CEC3D ProjectSection(SolutionItems) = preProject test\Common\ArrayOutput.cs = test\Common\ArrayOutput.cs test\Common\TaskExtensions.cs = test\Common\TaskExtensions.cs - test\Common\XUnitLoggerProvider.cs = test\Common\XUnitLoggerProvider.cs EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "client-ts", "client-ts", "{3A76C5A2-79ED-49BC-8BDC-6A3A766FFA1B}" diff --git a/test/Common/XUnitLoggerProvider.cs b/test/Common/XUnitLoggerProvider.cs deleted file mode 100644 index 4bb70201a9..0000000000 --- a/test/Common/XUnitLoggerProvider.cs +++ /dev/null @@ -1,104 +0,0 @@ -// 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.AspNetCore.SignalR.Tests; -using Microsoft.Extensions.Logging; -using System; -using System.Linq; -using Xunit.Abstractions; - -namespace Microsoft.Extensions.Logging -{ - public static class XUnitLoggerFactoryExtensions - { - public static void AddXUnit(this ILoggerFactory self, ITestOutputHelper output) - { - self.AddProvider(new XUnitLoggerProvider(output)); - } - - public static void AddXUnit(this ILoggerFactory self, ITestOutputHelper output, LogLevel minLevel) - { - self.AddProvider(new XUnitLoggerProvider(output, minLevel)); - } - } -} - -namespace Microsoft.AspNetCore.SignalR.Tests -{ - public class XUnitLoggerProvider : ILoggerProvider - { - private ITestOutputHelper _output; - private LogLevel _minLevel; - - public XUnitLoggerProvider(ITestOutputHelper output) - : this(output, LogLevel.Trace) - { - } - - public XUnitLoggerProvider(ITestOutputHelper output, LogLevel minLevel) - { - _output = output; - _minLevel = minLevel; - } - - public ILogger CreateLogger(string categoryName) - { - return new XUnitLogger(_output, categoryName, _minLevel); - } - - public void Dispose() - { - } - } - - public class XUnitLogger : ILogger, IDisposable - { - private readonly string _category; - private readonly LogLevel _minLogLevel; - private readonly ITestOutputHelper _output; - private bool _disposed; - - public XUnitLogger(ITestOutputHelper output, string category, LogLevel minLogLevel) - { - _minLogLevel = minLogLevel; - _category = category; - _output = output; - } - - public void Log( - LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) - { - if (!IsEnabled(logLevel)) - { - return; - } - var firstLinePrefix = $"| {_category} {logLevel}: "; - var lines = formatter(state, exception).Split('\n'); - _output.WriteLine(firstLinePrefix + lines.First()); - - var additionalLinePrefix = "|" + new string(' ', firstLinePrefix.Length - 1); - foreach (var line in lines.Skip(1)) - { - _output.WriteLine(additionalLinePrefix + line.Trim('\r')); - } - } - - public bool IsEnabled(LogLevel logLevel) - => logLevel >= _minLogLevel && !_disposed; - - public IDisposable BeginScope(TState state) - => new NullScope(); - - private class NullScope : IDisposable - { - public void Dispose() - { - } - } - - public void Dispose() - { - _disposed = true; - } - } -} diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/Microsoft.AspNetCore.SignalR.Client.Tests.csproj b/test/Microsoft.AspNetCore.SignalR.Client.Tests/Microsoft.AspNetCore.SignalR.Client.Tests.csproj index c33f6d632a..57ff233183 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/Microsoft.AspNetCore.SignalR.Client.Tests.csproj +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/Microsoft.AspNetCore.SignalR.Client.Tests.csproj @@ -13,7 +13,6 @@ - diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs index 5a8e346574..aa80e4099e 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs @@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests const string message = "Major Key"; var baseUrl = _serverFixture.BaseUrl; var loggerFactory = new LoggerFactory(); - loggerFactory.AddXUnit(_output, LogLevel.Trace); + loggerFactory.AddXunit(_output, LogLevel.Trace); var transport = transportFactory(loggerFactory); @@ -134,7 +134,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests { var baseUrl = _serverFixture.BaseUrl; var loggerFactory = new LoggerFactory(); - loggerFactory.AddXUnit(_output, LogLevel.Debug); + loggerFactory.AddXunit(_output, LogLevel.Debug); var connection = new ClientConnection(new Uri(baseUrl + "/echo"), loggerFactory); try diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/Microsoft.AspNetCore.SignalR.Tests.csproj b/test/Microsoft.AspNetCore.SignalR.Tests/Microsoft.AspNetCore.SignalR.Tests.csproj index 0203bbe189..3cfdcc986f 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/Microsoft.AspNetCore.SignalR.Tests.csproj +++ b/test/Microsoft.AspNetCore.SignalR.Tests/Microsoft.AspNetCore.SignalR.Tests.csproj @@ -14,7 +14,6 @@ - @@ -31,6 +30,7 @@ + diff --git a/test/Microsoft.AspNetCore.WebSockets.Internal.ConformanceTest/AutobahnTests.cs b/test/Microsoft.AspNetCore.WebSockets.Internal.ConformanceTest/AutobahnTests.cs index 43a1bddbb0..9ea7ddb61a 100644 --- a/test/Microsoft.AspNetCore.WebSockets.Internal.ConformanceTest/AutobahnTests.cs +++ b/test/Microsoft.AspNetCore.WebSockets.Internal.ConformanceTest/AutobahnTests.cs @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.WebSockets.Internal.ConformanceTest if (string.Equals(Environment.GetEnvironmentVariable("AUTOBAHN_SUITES_LOG"), "1", StringComparison.Ordinal)) { - loggerFactory.AddXUnit(_output); + loggerFactory.AddXunit(_output); loggerFactory.AddConsole(); _output.WriteLine("Logging enabled"); } diff --git a/test/Microsoft.AspNetCore.WebSockets.Internal.ConformanceTest/Microsoft.AspNetCore.WebSockets.Internal.ConformanceTest.csproj b/test/Microsoft.AspNetCore.WebSockets.Internal.ConformanceTest/Microsoft.AspNetCore.WebSockets.Internal.ConformanceTest.csproj index 881d8d0692..c803c32bbf 100644 --- a/test/Microsoft.AspNetCore.WebSockets.Internal.ConformanceTest/Microsoft.AspNetCore.WebSockets.Internal.ConformanceTest.csproj +++ b/test/Microsoft.AspNetCore.WebSockets.Internal.ConformanceTest/Microsoft.AspNetCore.WebSockets.Internal.ConformanceTest.csproj @@ -7,14 +7,12 @@ true true - - - +