网站首页 网站源码
website
站点相关全部源代码,隐藏了一些关于服务器的信息
using Microsoft.Extensions.Logging;
using Xunit.Abstractions;

namespace Dzp.Core.XunitBasic;

public class XunitLoggerProvider(ITestOutputHelper testOutputHelper) : ILoggerProvider
{
    public ILogger CreateLogger(string categoryName)
        => new XunitLogger(testOutputHelper, categoryName);

    public void Dispose()
    {
    }
}

public class XunitLogger(ITestOutputHelper testOutputHelper, string categoryName) : ILogger
{
    public IDisposable BeginScope<TState>(TState state)
        where TState : notnull
        => 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()
        {
        }
    }
}
loading