mirror of
https://github.com/bitwarden/server.git
synced 2026-01-31 14:13:18 +08:00
48 lines
1.1 KiB
C#
48 lines
1.1 KiB
C#
|
|
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)}");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|