2024-04-30 14:43:14 +08:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2024-04-28 22:02:29 +08:00
|
|
|
|
using Xunit.Abstractions;
|
|
|
|
|
|
|
|
|
|
namespace Canon.Tests.Utils;
|
|
|
|
|
|
2024-04-30 14:43:14 +08:00
|
|
|
|
public class TestLogger<T>(ITestOutputHelper testOutputHelper) : ILogger<T>, IDisposable
|
2024-04-28 22:02:29 +08:00
|
|
|
|
{
|
|
|
|
|
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception,
|
|
|
|
|
Func<TState, Exception?, string> formatter)
|
|
|
|
|
{
|
2024-04-30 14:43:14 +08:00
|
|
|
|
testOutputHelper.WriteLine("{0}: {1}", logLevel, formatter(state, exception));
|
2024-04-28 22:02:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-30 14:43:14 +08:00
|
|
|
|
public bool IsEnabled(LogLevel logLevel) => false;
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IDisposable BeginScope<TState>(TState state) where TState : notnull
|
|
|
|
|
{
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2024-04-28 22:02:29 +08:00
|
|
|
|
}
|