namespace Divergic.Logging.Xunit { using System; using global::Xunit.Abstractions; using Microsoft.Extensions.Logging; /// /// The /// class is used to provide a simple logging bootstrap class for xUnit test classes. /// public abstract class LoggingTestsBase : IDisposable { /// /// Initializes a new instance of the class. /// /// The xUnit test output. /// The minimum log level to output. protected LoggingTestsBase(ITestOutputHelper output, LogLevel logLevel) { Output = output ?? throw new ArgumentNullException(nameof(output)); Logger = output.BuildLoggerFor(logLevel); } /// /// Initializes a new instance of the class. /// /// The xUnit test output. /// Optional logging configuration. protected LoggingTestsBase(ITestOutputHelper output, LoggingConfig? config = null) { Output = output ?? throw new ArgumentNullException(nameof(output)); Logger = output.BuildLoggerFor(config); } /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } /// /// Disposes resources held by this instance. /// /// true if disposing unmanaged types; otherwise false. protected virtual void Dispose(bool disposing) { if (disposing) { Logger.Dispose(); } } /// /// Gets the logger instance. /// protected ICacheLogger Logger { get; } /// /// Gets the xUnit test output. /// protected ITestOutputHelper Output { get; } } }