You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.1 KiB
47 lines
1.1 KiB
using Microsoft.Extensions.Logging; |
|
using Xunit; |
|
|
|
namespace Bit.Infrastructure.IntegrationTest; |
|
|
|
public sealed class XUnitLoggerProvider : ILoggerProvider |
|
{ |
|
public ILogger CreateLogger(string categoryName) |
|
{ |
|
return new XUnitLogger(categoryName); |
|
} |
|
|
|
public void Dispose() |
|
{ |
|
|
|
} |
|
|
|
private class XUnitLogger : ILogger |
|
{ |
|
private readonly string _categoryName; |
|
|
|
public XUnitLogger(string categoryName) |
|
{ |
|
_categoryName = categoryName; |
|
} |
|
|
|
public IDisposable? BeginScope<TState>(TState state) where TState : notnull |
|
{ |
|
return null; |
|
} |
|
|
|
public bool IsEnabled(LogLevel logLevel) |
|
{ |
|
return true; |
|
} |
|
|
|
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter) |
|
{ |
|
if (TestContext.Current?.TestOutputHelper is not ITestOutputHelper testOutputHelper) |
|
{ |
|
return; |
|
} |
|
|
|
testOutputHelper.WriteLine($"[{_categoryName}] {formatter(state, exception)}"); |
|
} |
|
} |
|
}
|
|
|