using Microsoft.Extensions.Logging; using System; using Xunit.Abstractions; namespace k8s.Tests.Logging { /// /// Extension methods for logging to Xunit text output. /// public static class TestOutputLoggingExtensions { /// /// Log to test output. /// /// /// The global logging configuration. /// /// /// Output for the current test. /// /// /// The minimum level to log at. /// public static void AddTestOutput(this ILoggingBuilder logging, ITestOutputHelper testOutput, LogLevel minLogLevel = LogLevel.Information) { if (logging == null) { throw new ArgumentNullException(nameof(logging)); } if (testOutput == null) { throw new ArgumentNullException(nameof(testOutput)); } logging.AddProvider( new TestOutputLoggerProvider(testOutput, minLogLevel)); } /// /// Log to test output. /// /// /// The logger factory. /// /// /// Output for the current test. /// /// /// The minimum level to log at. /// /// /// The logger factory (enables inline use / method-chaining). /// public static ILoggerFactory AddTestOutput(this ILoggerFactory loggers, ITestOutputHelper testOutput, LogLevel minLogLevel = LogLevel.Information) { if (loggers == null) { throw new ArgumentNullException(nameof(loggers)); } if (testOutput == null) { throw new ArgumentNullException(nameof(testOutput)); } loggers.AddProvider( new TestOutputLoggerProvider(testOutput, minLogLevel)); return loggers; } } }