* all net5 * var * SA1310 * SA1310 * allow 1031 * SA1805 * fix SA1642 * remove unused code * allow sa1405 * isempty * fix CA1714 * fix CA1806 * remove always false if * fix format * fix CA1062 * allow SA0001 * fix CA1062 * allow ca1034 and temp allow ca1835 * fix 16XX doc related warnings * elm SA16XX * elm SA16XX * fix CA2213 * revert to pass all test * move unclear rule to ruleset * follow up of moving ruleset * remove this * fix test flaky
63 lines
1.9 KiB
C#
63 lines
1.9 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace k8s.Tests.Logging
|
|
{
|
|
/// <summary>
|
|
/// Logger provider for logging to Xunit test output.
|
|
/// </summary>
|
|
internal sealed class TestOutputLoggerProvider
|
|
: ILoggerProvider
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="TestOutputLoggerProvider"/> class.
|
|
/// Create a new <see cref="TestOutputLoggerProvider"/>.
|
|
/// </summary>
|
|
/// <param name="testOutput">
|
|
/// The output for the current test.
|
|
/// </param>
|
|
/// <param name="minLogLevel">
|
|
/// The logger's minimum log level.
|
|
/// </param>
|
|
public TestOutputLoggerProvider(ITestOutputHelper testOutput, LogLevel minLogLevel)
|
|
{
|
|
if (testOutput == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(testOutput));
|
|
}
|
|
|
|
TestOutput = testOutput;
|
|
MinLogLevel = minLogLevel;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Dispose of resources being used by the logger provider.
|
|
/// </summary>
|
|
public void Dispose()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// The output for the current test.
|
|
/// </summary>
|
|
private ITestOutputHelper TestOutput { get; }
|
|
|
|
/// <summary>
|
|
/// The logger's minimum log level.
|
|
/// </summary>
|
|
public LogLevel MinLogLevel { get; }
|
|
|
|
/// <summary>
|
|
/// Create a new logger.
|
|
/// </summary>
|
|
/// <param name="categoryName">
|
|
/// The logger category name.
|
|
/// </param>
|
|
/// <returns>
|
|
/// The logger, as an <see cref="ILogger"/>.
|
|
/// </returns>
|
|
public ILogger CreateLogger(string categoryName) => new TestOutputLogger(TestOutput, categoryName, MinLogLevel);
|
|
}
|
|
}
|