parent
af22fec225
commit
fb512bbf41
|
|
@ -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}"
|
||||
|
|
|
|||
|
|
@ -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<TState>(
|
||||
LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> 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>(TState state)
|
||||
=> new NullScope();
|
||||
|
||||
private class NullScope : IDisposable
|
||||
{
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -13,7 +13,6 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="..\Common\TaskExtensions.cs" Link="TaskExtensions.cs" />
|
||||
<Compile Include="..\Common\ArrayOutput.cs" Link="ArrayOutput.cs" />
|
||||
<Compile Include="..\Common\XUnitLoggerProvider.cs" Link="XUnitLoggerProvider.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\Common\TaskExtensions.cs" Link="TaskExtensions.cs" />
|
||||
<Compile Include="..\Common\XUnitLoggerProvider.cs" Link="XUnitLoggerProvider.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -31,6 +30,7 @@
|
|||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Testing" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
|
||||
<PackageReference Include="Moq" Version="$(MoqVersion)" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,14 +7,12 @@
|
|||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\Common\XUnitLoggerProvider.cs" Link="XUnitLoggerProvider.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Server.IntegrationTesting" Version="$(AspNetCoreLabsVersion)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Testing" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Testing" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="$(JsonNetVersion)" />
|
||||
|
|
|
|||
Loading…
Reference in New Issue