Skip to content

Commit

Permalink
chore: Added missing CreateLogger overloads (#18)
Browse files Browse the repository at this point in the history
* chore: Added missing `CreateLogger` overloads

* fix(style): Removed unused using
  • Loading branch information
samtrion authored May 23, 2024
1 parent 7650cc1 commit 33ab423
Showing 1 changed file with 59 additions and 1 deletion.
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

0 comments on commit 33ab423

Please sign in to comment.