38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace Elsa.Testing.Shared;
|
|
|
|
public class XunitLogger : ILogger
|
|
{
|
|
private readonly ITestOutputHelper _testOutputHelper;
|
|
private readonly string _categoryName;
|
|
|
|
public XunitLogger(ITestOutputHelper testOutputHelper, string categoryName)
|
|
{
|
|
_testOutputHelper = testOutputHelper;
|
|
_categoryName = categoryName;
|
|
}
|
|
|
|
public IDisposable BeginScope<TState>(TState state) => NoopDisposable.Instance;
|
|
|
|
public bool IsEnabled(LogLevel logLevel)
|
|
=> true;
|
|
|
|
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
|
|
{
|
|
_testOutputHelper.WriteLine($"{_categoryName} [{eventId}] {formatter(state, exception)}");
|
|
|
|
if (exception != null)
|
|
_testOutputHelper.WriteLine(exception.ToString());
|
|
}
|
|
|
|
private class NoopDisposable : IDisposable
|
|
{
|
|
public static readonly NoopDisposable Instance = new NoopDisposable();
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
}
|
|
} |