Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 59 additions & 1 deletion src/NetEvolve.Logging.XUnit/XUnitLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Globalization;
using System.Text;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;
using NetEvolve.Arguments;
using NetEvolve.Logging.Abstractions;
using Xunit.Abstractions;
Expand Down Expand Up @@ -35,6 +34,19 @@ public class XUnitLogger : ILogger, ISupportExternalScope
/// <inheritdoc cref="IHasLoggedMessages.LoggedMessages"/>
public IReadOnlyList<LoggedMessage> LoggedMessages => _loggedMessages.AsReadOnly();

/// <summary>
/// Creates a new instance of <see cref="XUnitLogger"/>.
/// </summary>
/// <param name="messageSink">The <see cref="IMessageSink" /> to write the log messages to.</param>
/// <param name="scopeProvider">The <see cref="IExternalScopeProvider" /> to use to get the current scope.</param>
/// <param name="options">The options to control the behavior of the logger.</param>
/// <returns>A cached or new instance of <see cref="XUnitLogger"/>.</returns>
public static XUnitLogger CreateLogger(
IMessageSink messageSink,
IExternalScopeProvider? scopeProvider = null,
IXUnitLoggerOptions? options = null
) => CreateLogger(messageSink, TimeProvider.System, scopeProvider, options);

/// <summary>
/// Creates a new instance of <see cref="XUnitLogger"/>.
/// </summary>
Expand All @@ -51,10 +63,26 @@ public static XUnitLogger CreateLogger(
)
{
Argument.ThrowIfNull(messageSink);
Argument.ThrowIfNull(timeProvider);

return new XUnitLogger(messageSink, timeProvider, scopeProvider, options);
}

/// <summary>
/// Creates a new instance of <see cref="XUnitLogger{T}"/>.
/// </summary>
/// <typeparam name="T">The type who's fullname is used as the category name for messages produced by the logger.</typeparam>
/// <param name="messageSink">The <see cref="IMessageSink" /> to write the log messages to.</param>
/// <param name="scopeProvider">The <see cref="IExternalScopeProvider" /> to use to get the current scope.</param>
/// <param name="options">The options to control the behavior of the logger.</param>
/// <returns>A cached or new instance of <see cref="XUnitLogger"/>.</returns>
public static XUnitLogger<T> CreateLogger<T>(
IMessageSink messageSink,
IExternalScopeProvider? scopeProvider = null,
IXUnitLoggerOptions? options = null
)
where T : notnull => CreateLogger<T>(messageSink, scopeProvider, options);

/// <summary>
/// Creates a new instance of <see cref="XUnitLogger{T}"/>.
/// </summary>
Expand All @@ -72,6 +100,19 @@ public static XUnitLogger<T> CreateLogger<T>(
)
where T : notnull => new XUnitLogger<T>(messageSink, timeProvider, scopeProvider, options);

/// <summary>
/// Creates a new instance of <see cref="XUnitLogger"/>.
/// </summary>
/// <param name="testOutputHelper">The <see cref="ITestOutputHelper" /> to write the log messages to.</param>
/// <param name="scopeProvider">The <see cref="IExternalScopeProvider" /> to use to get the current scope.</param>
/// <param name="options">The options to control the behavior of the logger.</param>
/// <returns>A cached or new instance of <see cref="XUnitLogger"/>.</returns>
public static XUnitLogger CreateLogger(
ITestOutputHelper testOutputHelper,
IExternalScopeProvider? scopeProvider = null,
IXUnitLoggerOptions? options = null
) => CreateLogger(testOutputHelper, TimeProvider.System, scopeProvider, options);

/// <summary>
/// Creates a new instance of <see cref="XUnitLogger"/>.
/// </summary>
Expand All @@ -88,10 +129,27 @@ public static XUnitLogger CreateLogger(
)
{
Argument.ThrowIfNull(testOutputHelper);
Argument.ThrowIfNull(timeProvider);

return new XUnitLogger(testOutputHelper, timeProvider, scopeProvider, options);
}

/// <summary>
/// Creates a new instance of <see cref="XUnitLogger{T}"/>.
/// </summary>
/// <typeparam name="T">The type who's fullname is used as the category name for messages produced by the logger.</typeparam>
/// <param name="testOutputHelper">The <see cref="ITestOutputHelper" /> to write the log messages to.</param>
/// <param name="scopeProvider">The <see cref="IExternalScopeProvider" /> to use to get the current scope.</param>
/// <param name="options">The options to control the behavior of the logger.</param>
/// <returns>A cached or new instance of <see cref="XUnitLogger"/>.</returns>
public static XUnitLogger<T> CreateLogger<T>(
ITestOutputHelper testOutputHelper,
IExternalScopeProvider? scopeProvider = null,
IXUnitLoggerOptions? options = null
)
where T : notnull =>
CreateLogger<T>(testOutputHelper, TimeProvider.System, scopeProvider, options);

/// <summary>
/// Creates a new instance of <see cref="XUnitLogger{T}"/>.
/// </summary>
Expand Down