namespace Microsoft.Extensions.Logging
{
using System;
using Divergic.Logging.Xunit;
using Xunit.Abstractions;
///
/// The
/// class provides extension methods for configuring with providers.
///
public static class LoggerFactoryExtensions
{
///
/// Registers the in the factory using the specified
/// .
///
/// The factory to add the provider to.
/// The test output reference.
/// Optional logging configuration.
/// The logger factory.
/// The is null.
/// The is null.
public static ILoggerFactory AddXunit(this ILoggerFactory factory, ITestOutputHelper output,
LoggingConfig? config = null)
{
factory = factory ?? throw new ArgumentNullException(nameof(factory));
output = output ?? throw new ArgumentNullException(nameof(output));
#pragma warning disable CA2000 // Dispose objects before losing scope
var provider = new TestOutputLoggerProvider(output, config);
#pragma warning restore CA2000 // Dispose objects before losing scope
#pragma warning disable CA1062 // Validate arguments of public methods
factory.AddProvider(provider);
#pragma warning restore CA1062 // Validate arguments of public methods
return factory;
}
}
}