diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
index 4650ceeb..18f174f9 100644
--- a/.github/CONTRIBUTING.md
+++ b/.github/CONTRIBUTING.md
@@ -1,3 +1,5 @@
+# Contributing
+
To contribute changes (source code, scripts, configuration) to this repository please follow the steps below. These steps are a guideline for contributing and do not necessarily need to be followed for all changes.
1. If you intend to fix a bug please create an issue before forking the repository.
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
index a62cc337..26ccddc7 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.md
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -2,7 +2,6 @@
name: Bug report
about: Create a bug report to help us improve the library
labels: bug
-
---
### Describe the bug
@@ -32,11 +31,11 @@ A clear and concise description of what actually happened. If an exception occur
### System information
### Additional context
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
index 0086358d..3e6c89ff 100644
--- a/.github/ISSUE_TEMPLATE/config.yml
+++ b/.github/ISSUE_TEMPLATE/config.yml
@@ -1 +1,5 @@
blank_issues_enabled: true
+contact_links:
+ - name: Contact me
+ url: https://twitter.com/martin_costello
+ about: You can also contact me on Twitter.
diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md
index ac06481c..9ec65944 100644
--- a/.github/ISSUE_TEMPLATE/feature_request.md
+++ b/.github/ISSUE_TEMPLATE/feature_request.md
@@ -2,7 +2,6 @@
name: Feature request
about: Suggest an idea for a feature of this library
labels: feature-request
-
---
### Is your feature request related to a problem? Please describe.
diff --git a/Directory.Build.props b/Directory.Build.props
index e80fddcf..c2cc85fa 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -44,8 +44,8 @@
snupkg
true
true
- 0.3.0.0
- 0.3.1
+ 0.4.0.0
+ 0.4.0
beta$([System.Convert]::ToInt32(`$(GITHUB_RUN_NUMBER)`).ToString(`0000`))
$(GITHUB_REF.Replace('refs/tags/v', ''))
diff --git a/Logging.XUnit.sln b/Logging.XUnit.sln
index 286f207c..413e81cc 100644
--- a/Logging.XUnit.sln
+++ b/Logging.XUnit.sln
@@ -28,10 +28,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{278BCCB1
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{D0426D09-1FF8-4E1F-A9AF-38DDEE5D7CCA}"
ProjectSection(SolutionItems) = preProject
+ .github\actionlint-matcher.json = .github\actionlint-matcher.json
+ .github\CODEOWNERS = .github\CODEOWNERS
.github\CONTRIBUTING.md = .github\CONTRIBUTING.md
+ .github\dependabot.yml = .github\dependabot.yml
+ .github\FUNDING.yml = .github\FUNDING.yml
.github\ISSUE_TEMPLATE.md = .github\ISSUE_TEMPLATE.md
.github\PULL_REQUEST_TEMPLATE.md = .github\PULL_REQUEST_TEMPLATE.md
- .github\stale.yml = .github\stale.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".vscode", ".vscode", "{701E574A-6366-4AF9-9319-237968FA1089}"
@@ -43,6 +46,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ISSUE_TEMPLATE", "ISSUE_TEMPLATE", "{F37263E7-6656-4A2B-B02E-538B5F9970BD}"
ProjectSection(SolutionItems) = preProject
.github\ISSUE_TEMPLATE\bug_report.md = .github\ISSUE_TEMPLATE\bug_report.md
+ .github\ISSUE_TEMPLATE\config.yml = .github\ISSUE_TEMPLATE\config.yml
.github\ISSUE_TEMPLATE\feature_request.md = .github\ISSUE_TEMPLATE\feature_request.md
EndProjectSection
EndProject
@@ -55,7 +59,10 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{7764A046-DEE7-4D88-83E2-537DB7767123}"
ProjectSection(SolutionItems) = preProject
.github\workflows\build.yml = .github\workflows\build.yml
- .github\workflows\update-dotnet-sdk.yml = .github\workflows\update-dotnet-sdk.yml
+ .github\workflows\codeql-analysis.yml = .github\workflows\codeql-analysis.yml
+ .github\workflows\dependency-review.yml = .github\workflows\dependency-review.yml
+ .github\workflows\lint.yml = .github\workflows\lint.yml
+ .github\workflows\ossf-scorecard.yml = .github\workflows\ossf-scorecard.yml
EndProjectSection
EndProject
Global
diff --git a/src/Logging.XUnit/IMessageSinkExtensions.cs b/src/Logging.XUnit/IMessageSinkExtensions.cs
index 4a2cb6af..df340d10 100644
--- a/src/Logging.XUnit/IMessageSinkExtensions.cs
+++ b/src/Logging.XUnit/IMessageSinkExtensions.cs
@@ -24,10 +24,14 @@ public static class IMessageSinkExtensions
///
public static ILoggerFactory ToLoggerFactory(this IMessageSink messageSink)
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(messageSink);
+#else
if (messageSink == null)
{
throw new ArgumentNullException(nameof(messageSink));
}
+#endif
return new LoggerFactory().AddXUnit(messageSink);
}
diff --git a/src/Logging.XUnit/ITestOutputHelperExtensions.cs b/src/Logging.XUnit/ITestOutputHelperExtensions.cs
index fde33634..49b2e379 100644
--- a/src/Logging.XUnit/ITestOutputHelperExtensions.cs
+++ b/src/Logging.XUnit/ITestOutputHelperExtensions.cs
@@ -24,10 +24,14 @@ public static class ITestOutputHelperExtensions
///
public static ILoggerFactory ToLoggerFactory(this ITestOutputHelper outputHelper)
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(outputHelper);
+#else
if (outputHelper == null)
{
throw new ArgumentNullException(nameof(outputHelper));
}
+#endif
return new LoggerFactory().AddXUnit(outputHelper);
}
diff --git a/src/Logging.XUnit/MartinCostello.Logging.XUnit.csproj b/src/Logging.XUnit/MartinCostello.Logging.XUnit.csproj
index 35b17850..a5af682a 100644
--- a/src/Logging.XUnit/MartinCostello.Logging.XUnit.csproj
+++ b/src/Logging.XUnit/MartinCostello.Logging.XUnit.csproj
@@ -4,23 +4,29 @@
Extensions for Microsoft.Extensions.Logging for xunit.
true
true
- $(NoWarn)
Library
MartinCostello.Logging.XUnit
- 0.2.0
+ 0.3.0
MartinCostello.Logging.XUnit
$(Description)
- netstandard2.0
+ netstandard2.0;net8.0
xunit Logging Extensions
-
- True
+
+ true
+ true
+ true
+ true
+ true
+
+
+
<_Parameter1>af808007-f06a-410b-886d-152b3f39c43f
diff --git a/src/Logging.XUnit/XUnitLogScope.cs b/src/Logging.XUnit/XUnitLogScope.cs
index ba871cd3..f7c00f8a 100644
--- a/src/Logging.XUnit/XUnitLogScope.cs
+++ b/src/Logging.XUnit/XUnitLogScope.cs
@@ -37,7 +37,7 @@ internal static XUnitLogScope? Current
internal XUnitLogScope? Parent { get; private set; }
///
- public override string ToString()
+ public override string? ToString()
=> State.ToString();
///
diff --git a/src/Logging.XUnit/XUnitLogger.cs b/src/Logging.XUnit/XUnitLogger.cs
index e8b4c0e9..61f8da96 100644
--- a/src/Logging.XUnit/XUnitLogger.cs
+++ b/src/Logging.XUnit/XUnitLogger.cs
@@ -56,7 +56,7 @@ private XUnitLogger(string name, XUnitLoggerOptions? options)
Name = name ?? throw new ArgumentNullException(nameof(name));
_filter = options?.Filter ?? (static (_, _) => true);
- _messageSinkMessageFactory = options?.MessageSinkMessageFactory ?? (message => new DiagnosticMessage(message));
+ _messageSinkMessageFactory = options?.MessageSinkMessageFactory ?? (static (message) => new DiagnosticMessage(message));
_timestampFormat = options?.TimestampFormat ?? "u";
IncludeScopes = options?.IncludeScopes ?? false;
}
@@ -89,12 +89,17 @@ private XUnitLogger(string name, XUnitLoggerOptions? options)
internal Func Clock { get; set; } = static () => DateTimeOffset.Now;
///
- public IDisposable BeginScope(TState state)
+ public IDisposable? BeginScope(TState state)
+ where TState : notnull
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(state);
+#else
if (state == null)
{
throw new ArgumentNullException(nameof(state));
}
+#endif
return XUnitLogScope.Push(state);
}
@@ -111,17 +116,21 @@ public bool IsEnabled(LogLevel logLevel)
}
///
- public void Log(LogLevel logLevel, EventId eventId, TState? state, Exception? exception, Func formatter)
+ public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter)
{
if (!IsEnabled(logLevel))
{
return;
}
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(formatter);
+#else
if (formatter == null)
{
throw new ArgumentNullException(nameof(formatter));
}
+#endif
string? message = formatter(state, exception);
@@ -283,7 +292,7 @@ private static void GetScopeInformation(StringBuilder builder)
///
/// The to stringify.
/// An enumeration of scope properties from the current scope.
- private static IEnumerable StringifyScope(XUnitLogScope scope)
+ private static IEnumerable StringifyScope(XUnitLogScope scope)
{
if (scope.State is IEnumerable> pairs)
{
diff --git a/src/Logging.XUnit/XUnitLoggerExtensions.IMessageSink.cs b/src/Logging.XUnit/XUnitLoggerExtensions.IMessageSink.cs
index 058dacfd..8bc36751 100644
--- a/src/Logging.XUnit/XUnitLoggerExtensions.IMessageSink.cs
+++ b/src/Logging.XUnit/XUnitLoggerExtensions.IMessageSink.cs
@@ -25,6 +25,10 @@ public static partial class XUnitLoggerExtensions
///
public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, IMessageSinkAccessor accessor)
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentNullException.ThrowIfNull(accessor);
+#else
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
@@ -34,6 +38,7 @@ public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, IMessageSin
{
throw new ArgumentNullException(nameof(accessor));
}
+#endif
return builder.AddXUnit(accessor, static (_) => { });
}
@@ -52,6 +57,11 @@ public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, IMessageSin
///
public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, IMessageSinkAccessor accessor, Action configure)
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentNullException.ThrowIfNull(accessor);
+ ArgumentNullException.ThrowIfNull(configure);
+#else
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
@@ -66,12 +76,15 @@ public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, IMessageSin
{
throw new ArgumentNullException(nameof(configure));
}
+#endif
var options = new XUnitLoggerOptions();
configure(options);
+#pragma warning disable CA2000
builder.AddProvider(new XUnitLoggerProvider(accessor, options));
+#pragma warning restore CA2000
builder.Services.TryAddSingleton(accessor);
@@ -91,6 +104,10 @@ public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, IMessageSin
///
public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, IMessageSink messageSink)
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentNullException.ThrowIfNull(messageSink);
+#else
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
@@ -100,6 +117,7 @@ public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, IMessageSin
{
throw new ArgumentNullException(nameof(messageSink));
}
+#endif
return builder.AddXUnit(messageSink, static (_) => { });
}
@@ -118,6 +136,11 @@ public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, IMessageSin
///
public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, IMessageSink messageSink, Action configure)
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentNullException.ThrowIfNull(messageSink);
+ ArgumentNullException.ThrowIfNull(configure);
+#else
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
@@ -132,12 +155,15 @@ public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, IMessageSin
{
throw new ArgumentNullException(nameof(configure));
}
+#endif
var options = new XUnitLoggerOptions();
configure(options);
+#pragma warning disable CA2000
return builder.AddProvider(new XUnitLoggerProvider(messageSink, options));
+#pragma warning restore CA2000
}
///
@@ -154,6 +180,10 @@ public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, IMessageSin
///
public static ILoggerFactory AddXUnit(this ILoggerFactory factory, IMessageSink messageSink, LogLevel minLevel)
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(factory);
+ ArgumentNullException.ThrowIfNull(messageSink);
+#else
if (factory == null)
{
throw new ArgumentNullException(nameof(factory));
@@ -163,6 +193,7 @@ public static ILoggerFactory AddXUnit(this ILoggerFactory factory, IMessageSink
{
throw new ArgumentNullException(nameof(messageSink));
}
+#endif
return factory.AddXUnit(messageSink, (_, level) => level >= minLevel);
}
@@ -181,6 +212,11 @@ public static ILoggerFactory AddXUnit(this ILoggerFactory factory, IMessageSink
///
public static ILoggerFactory AddXUnit(this ILoggerFactory factory, IMessageSink messageSink, Func filter)
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(factory);
+ ArgumentNullException.ThrowIfNull(messageSink);
+ ArgumentNullException.ThrowIfNull(filter);
+#else
if (factory == null)
{
throw new ArgumentNullException(nameof(factory));
@@ -195,6 +231,7 @@ public static ILoggerFactory AddXUnit(this ILoggerFactory factory, IMessageSink
{
throw new ArgumentNullException(nameof(filter));
}
+#endif
return factory.AddXUnit(messageSink, (options) => options.Filter = filter);
}
@@ -212,6 +249,10 @@ public static ILoggerFactory AddXUnit(this ILoggerFactory factory, IMessageSink
///
public static ILoggerFactory AddXUnit(this ILoggerFactory factory, IMessageSink messageSink)
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(factory);
+ ArgumentNullException.ThrowIfNull(messageSink);
+#else
if (factory == null)
{
throw new ArgumentNullException(nameof(factory));
@@ -221,6 +262,7 @@ public static ILoggerFactory AddXUnit(this ILoggerFactory factory, IMessageSink
{
throw new ArgumentNullException(nameof(messageSink));
}
+#endif
return factory.AddXUnit(messageSink, static (_) => { });
}
@@ -239,6 +281,11 @@ public static ILoggerFactory AddXUnit(this ILoggerFactory factory, IMessageSink
///
public static ILoggerFactory AddXUnit(this ILoggerFactory factory, IMessageSink messageSink, XUnitLoggerOptions options)
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(factory);
+ ArgumentNullException.ThrowIfNull(messageSink);
+ ArgumentNullException.ThrowIfNull(options);
+#else
if (factory == null)
{
throw new ArgumentNullException(nameof(factory));
@@ -253,6 +300,7 @@ public static ILoggerFactory AddXUnit(this ILoggerFactory factory, IMessageSink
{
throw new ArgumentNullException(nameof(options));
}
+#endif
return factory.AddXUnit(messageSink, () => options);
}
@@ -271,6 +319,11 @@ public static ILoggerFactory AddXUnit(this ILoggerFactory factory, IMessageSink
///
public static ILoggerFactory AddXUnit(this ILoggerFactory factory, IMessageSink messageSink, Action configure)
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(factory);
+ ArgumentNullException.ThrowIfNull(messageSink);
+ ArgumentNullException.ThrowIfNull(configure);
+#else
if (factory == null)
{
throw new ArgumentNullException(nameof(factory));
@@ -285,15 +338,14 @@ public static ILoggerFactory AddXUnit(this ILoggerFactory factory, IMessageSink
{
throw new ArgumentNullException(nameof(configure));
}
+#endif
- return factory.AddXUnit(
- messageSink,
- () =>
- {
- var options = new XUnitLoggerOptions();
- configure(options);
- return options;
- });
+ return factory.AddXUnit(messageSink, () =>
+ {
+ var options = new XUnitLoggerOptions();
+ configure(options);
+ return options;
+ });
}
///
@@ -310,6 +362,11 @@ public static ILoggerFactory AddXUnit(this ILoggerFactory factory, IMessageSink
///
public static ILoggerFactory AddXUnit(this ILoggerFactory factory, IMessageSink messageSink, Func configure)
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(factory);
+ ArgumentNullException.ThrowIfNull(messageSink);
+ ArgumentNullException.ThrowIfNull(configure);
+#else
if (factory == null)
{
throw new ArgumentNullException(nameof(factory));
@@ -324,10 +381,13 @@ public static ILoggerFactory AddXUnit(this ILoggerFactory factory, IMessageSink
{
throw new ArgumentNullException(nameof(configure));
}
+#endif
var options = configure();
+#pragma warning disable CA2000
factory.AddProvider(new XUnitLoggerProvider(messageSink, options));
+#pragma warning restore CA2000
return factory;
}
diff --git a/src/Logging.XUnit/XUnitLoggerExtensions.ITestOutputHelper.cs b/src/Logging.XUnit/XUnitLoggerExtensions.ITestOutputHelper.cs
index 29df11bd..d0fc54f3 100644
--- a/src/Logging.XUnit/XUnitLoggerExtensions.ITestOutputHelper.cs
+++ b/src/Logging.XUnit/XUnitLoggerExtensions.ITestOutputHelper.cs
@@ -26,10 +26,14 @@ public static partial class XUnitLoggerExtensions
///
public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder)
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(builder);
+#else
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
+#endif
return builder.AddXUnit(new AmbientTestOutputHelperAccessor(), static (_) => { });
}
@@ -47,6 +51,10 @@ public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder)
///
public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, ITestOutputHelperAccessor accessor)
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentNullException.ThrowIfNull(accessor);
+#else
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
@@ -56,6 +64,7 @@ public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, ITestOutput
{
throw new ArgumentNullException(nameof(accessor));
}
+#endif
return builder.AddXUnit(accessor, static (_) => { });
}
@@ -74,6 +83,11 @@ public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, ITestOutput
///
public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, ITestOutputHelperAccessor accessor, Action configure)
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentNullException.ThrowIfNull(accessor);
+ ArgumentNullException.ThrowIfNull(configure);
+#else
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
@@ -88,12 +102,15 @@ public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, ITestOutput
{
throw new ArgumentNullException(nameof(configure));
}
+#endif
var options = new XUnitLoggerOptions();
configure(options);
+#pragma warning disable CA2000
builder.AddProvider(new XUnitLoggerProvider(accessor, options));
+#pragma warning restore CA2000
builder.Services.TryAddSingleton(accessor);
@@ -113,6 +130,10 @@ public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, ITestOutput
///
public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, ITestOutputHelper outputHelper)
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentNullException.ThrowIfNull(outputHelper);
+#else
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
@@ -122,6 +143,7 @@ public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, ITestOutput
{
throw new ArgumentNullException(nameof(outputHelper));
}
+#endif
return builder.AddXUnit(outputHelper, static (_) => { });
}
@@ -140,6 +162,11 @@ public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, ITestOutput
///
public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, ITestOutputHelper outputHelper, Action configure)
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentNullException.ThrowIfNull(outputHelper);
+ ArgumentNullException.ThrowIfNull(configure);
+#else
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
@@ -154,12 +181,15 @@ public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, ITestOutput
{
throw new ArgumentNullException(nameof(configure));
}
+#endif
var options = new XUnitLoggerOptions();
configure(options);
+#pragma warning disable CA2000
return builder.AddProvider(new XUnitLoggerProvider(outputHelper, options));
+#pragma warning restore CA2000
}
///
@@ -176,6 +206,10 @@ public static ILoggingBuilder AddXUnit(this ILoggingBuilder builder, ITestOutput
///
public static ILoggerFactory AddXUnit(this ILoggerFactory factory, ITestOutputHelper outputHelper, LogLevel minLevel)
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(factory);
+ ArgumentNullException.ThrowIfNull(outputHelper);
+#else
if (factory == null)
{
throw new ArgumentNullException(nameof(factory));
@@ -185,6 +219,7 @@ public static ILoggerFactory AddXUnit(this ILoggerFactory factory, ITestOutputHe
{
throw new ArgumentNullException(nameof(outputHelper));
}
+#endif
return factory.AddXUnit(outputHelper, (_, level) => level >= minLevel);
}
@@ -203,6 +238,11 @@ public static ILoggerFactory AddXUnit(this ILoggerFactory factory, ITestOutputHe
///
public static ILoggerFactory AddXUnit(this ILoggerFactory factory, ITestOutputHelper outputHelper, Func filter)
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(factory);
+ ArgumentNullException.ThrowIfNull(outputHelper);
+ ArgumentNullException.ThrowIfNull(filter);
+#else
if (factory == null)
{
throw new ArgumentNullException(nameof(factory));
@@ -217,6 +257,7 @@ public static ILoggerFactory AddXUnit(this ILoggerFactory factory, ITestOutputHe
{
throw new ArgumentNullException(nameof(filter));
}
+#endif
return factory.AddXUnit(outputHelper, (options) => options.Filter = filter);
}
@@ -234,6 +275,10 @@ public static ILoggerFactory AddXUnit(this ILoggerFactory factory, ITestOutputHe
///
public static ILoggerFactory AddXUnit(this ILoggerFactory factory, ITestOutputHelper outputHelper)
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(factory);
+ ArgumentNullException.ThrowIfNull(outputHelper);
+#else
if (factory == null)
{
throw new ArgumentNullException(nameof(factory));
@@ -243,6 +288,7 @@ public static ILoggerFactory AddXUnit(this ILoggerFactory factory, ITestOutputHe
{
throw new ArgumentNullException(nameof(outputHelper));
}
+#endif
return factory.AddXUnit(outputHelper, static (_) => { });
}
@@ -261,6 +307,11 @@ public static ILoggerFactory AddXUnit(this ILoggerFactory factory, ITestOutputHe
///
public static ILoggerFactory AddXUnit(this ILoggerFactory factory, ITestOutputHelper outputHelper, XUnitLoggerOptions options)
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(factory);
+ ArgumentNullException.ThrowIfNull(outputHelper);
+ ArgumentNullException.ThrowIfNull(options);
+#else
if (factory == null)
{
throw new ArgumentNullException(nameof(factory));
@@ -275,6 +326,7 @@ public static ILoggerFactory AddXUnit(this ILoggerFactory factory, ITestOutputHe
{
throw new ArgumentNullException(nameof(options));
}
+#endif
return factory.AddXUnit(outputHelper, () => options);
}
@@ -293,6 +345,11 @@ public static ILoggerFactory AddXUnit(this ILoggerFactory factory, ITestOutputHe
///
public static ILoggerFactory AddXUnit(this ILoggerFactory factory, ITestOutputHelper outputHelper, Action configure)
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(factory);
+ ArgumentNullException.ThrowIfNull(outputHelper);
+ ArgumentNullException.ThrowIfNull(configure);
+#else
if (factory == null)
{
throw new ArgumentNullException(nameof(factory));
@@ -307,15 +364,14 @@ public static ILoggerFactory AddXUnit(this ILoggerFactory factory, ITestOutputHe
{
throw new ArgumentNullException(nameof(configure));
}
+#endif
- return factory.AddXUnit(
- outputHelper,
- () =>
- {
- var options = new XUnitLoggerOptions();
- configure(options);
- return options;
- });
+ return factory.AddXUnit(outputHelper, () =>
+ {
+ var options = new XUnitLoggerOptions();
+ configure(options);
+ return options;
+ });
}
///
@@ -332,6 +388,11 @@ public static ILoggerFactory AddXUnit(this ILoggerFactory factory, ITestOutputHe
///
public static ILoggerFactory AddXUnit(this ILoggerFactory factory, ITestOutputHelper outputHelper, Func configure)
{
+#if NET8_0_OR_GREATER
+ ArgumentNullException.ThrowIfNull(factory);
+ ArgumentNullException.ThrowIfNull(outputHelper);
+ ArgumentNullException.ThrowIfNull(configure);
+#else
if (factory == null)
{
throw new ArgumentNullException(nameof(factory));
@@ -346,10 +407,13 @@ public static ILoggerFactory AddXUnit(this ILoggerFactory factory, ITestOutputHe
{
throw new ArgumentNullException(nameof(configure));
}
+#endif
var options = configure();
+#pragma warning disable CA2000
factory.AddProvider(new XUnitLoggerProvider(outputHelper, options));
+#pragma warning restore CA2000
return factory;
}
diff --git a/tests/Logging.XUnit.Tests/Integration/HttpServerFixture.cs b/tests/Logging.XUnit.Tests/Integration/HttpServerFixture.cs
index cd3ba1d1..e709b2c2 100644
--- a/tests/Logging.XUnit.Tests/Integration/HttpServerFixture.cs
+++ b/tests/Logging.XUnit.Tests/Integration/HttpServerFixture.cs
@@ -4,14 +4,13 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.Logging;
-using SampleApp;
namespace MartinCostello.Logging.XUnit.Integration;
///
/// A test fixture representing an HTTP server hosting the sample application. This class cannot be inherited.
///
-public sealed class HttpServerFixture : WebApplicationFactory, ITestOutputHelperAccessor
+public sealed class HttpServerFixture : WebApplicationFactory, ITestOutputHelperAccessor
{
///
public ITestOutputHelper? OutputHelper { get; set; }
diff --git a/tests/Logging.XUnit.Tests/MartinCostello.Logging.XUnit.Tests.csproj b/tests/Logging.XUnit.Tests/MartinCostello.Logging.XUnit.Tests.csproj
index 0c404434..f3aabe15 100644
--- a/tests/Logging.XUnit.Tests/MartinCostello.Logging.XUnit.Tests.csproj
+++ b/tests/Logging.XUnit.Tests/MartinCostello.Logging.XUnit.Tests.csproj
@@ -7,7 +7,7 @@
true
MartinCostello.Logging.XUnit
$(Description)
- net8.0
+ net8.0
diff --git a/tests/Logging.XUnit.Tests/XUnitLoggerTests.cs b/tests/Logging.XUnit.Tests/XUnitLoggerTests.cs
index a471d651..b9490de1 100644
--- a/tests/Logging.XUnit.Tests/XUnitLoggerTests.cs
+++ b/tests/Logging.XUnit.Tests/XUnitLoggerTests.cs
@@ -102,7 +102,7 @@ public static void XUnitLogger_BeginScope_Returns_Value()
var logger = new XUnitLogger(name, outputHelper, options);
// Act
- using IDisposable actual = logger.BeginScope(true);
+ using var actual = logger.BeginScope(true);
// Assert
actual.ShouldNotBeNull();
@@ -116,9 +116,10 @@ public static void XUnitLogger_BeginScope_Throws_If_State_Is_Null()
var outputHelper = Substitute.For();
var options = new XUnitLoggerOptions();
var logger = new XUnitLogger(name, outputHelper, options);
+ string state = null!;
// Act
- Assert.Throws("state", () => logger.BeginScope(null as string));
+ Assert.Throws("state", () => logger.BeginScope(state));
}
[Theory]
@@ -319,7 +320,7 @@ public static void XUnitLogger_Log_Logs_Message_If_Message_And_Exception()
new[] { "[2018-08-19 16:12:16Z] warn: MyName[3]", " Message|False|True", "System.InvalidOperationException: Invalid" });
// Act
- logger.Log(LogLevel.Warning, new EventId(3), null, exception, Formatter);
+ logger.Log(LogLevel.Warning, new EventId(3), null, exception, Formatter);
// Assert
outputHelper.Received(1).WriteLine(expected);
@@ -347,7 +348,7 @@ public static void XUnitLogger_Log_Logs_Message_If_Message_And_No_Exception()
new[] { "[2018-08-19 16:12:16Z] fail: MyName[4]", " Message|False|False" });
// Act
- logger.Log(LogLevel.Error, new EventId(4), null, null, Formatter);
+ logger.Log(LogLevel.Error, new EventId(4), null, null, Formatter);
// Assert
outputHelper.Received(1).WriteLine(expected);
@@ -431,7 +432,7 @@ public static void XUnitLogger_Log_Logs_Message_If_Scopes_Included_But_There_Are
new[] { "[2018-08-19 16:12:16Z] info: MyName[0]", " Message|False|False" });
// Act
- logger.Log(LogLevel.Information, 0, null, null, Formatter);
+ logger.Log(LogLevel.Information, 0, null, null, Formatter);
// Assert
outputHelper.Received(1).WriteLine(expected);
@@ -475,7 +476,7 @@ public static void XUnitLogger_Log_Logs_Message_If_Scopes_Included_And_There_Are
using (logger.BeginScope(null!))
#pragma warning restore CA2254
{
- logger.Log(LogLevel.Information, 0, null, null, Formatter);
+ logger.Log(LogLevel.Information, 0, null, null, Formatter);
}
}
}
@@ -515,7 +516,7 @@ public static void XUnitLogger_Log_Logs_Message_If_Scopes_Included_And_There_Is_
new KeyValuePair("ScopeKey", "ScopeValue"),
}))
{
- logger.Log(LogLevel.Information, 0, null, null, Formatter);
+ logger.Log(LogLevel.Information, 0, null, null, Formatter);
}
// Assert
@@ -556,7 +557,7 @@ public static void XUnitLogger_Log_Logs_Message_If_Scopes_Included_And_There_Is_
new KeyValuePair("ScopeKeyThree", "ScopeValueThree"),
}))
{
- logger.Log(LogLevel.Information, 0, null, null, Formatter);
+ logger.Log(LogLevel.Information, 0, null, null, Formatter);
}
// Assert
@@ -607,7 +608,7 @@ public static void XUnitLogger_Log_Logs_Message_If_Scopes_Included_And_There_Are
new KeyValuePair("ScopeKeySix", "ScopeValueSix"),
}))
{
- logger.Log(LogLevel.Information, 0, null, null, Formatter);
+ logger.Log(LogLevel.Information, 0, null, null, Formatter);
}
}
@@ -644,7 +645,7 @@ public static void XUnitLogger_Log_Logs_Message_If_Scopes_Included_And_There_Is_
// Act
using (logger.BeginScope(new[] { "ScopeKeyOne", "ScopeKeyTwo", "ScopeKeyThree" }))
{
- logger.Log(LogLevel.Information, 0, null, null, Formatter);
+ logger.Log(LogLevel.Information, 0, null, null, Formatter);
}
// Assert
diff --git a/tests/Logging.XUnit.Tests/xunit.runner.json b/tests/Logging.XUnit.Tests/xunit.runner.json
index ea67ff35..0d7484e1 100644
--- a/tests/Logging.XUnit.Tests/xunit.runner.json
+++ b/tests/Logging.XUnit.Tests/xunit.runner.json
@@ -1,6 +1,5 @@
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
"diagnosticMessages": true,
- "methodDisplay": "method",
- "methodDisplayOptions": "replaceUnderscoreWithSpace"
+ "methodDisplay": "method"
}
diff --git a/tests/SampleApp/FakeEntrypoint.cs b/tests/SampleApp/FakeEntrypoint.cs
deleted file mode 100644
index 96503bcd..00000000
--- a/tests/SampleApp/FakeEntrypoint.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-// Copyright (c) Martin Costello, 2018. All rights reserved.
-// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.
-
-namespace SampleApp;
-
-public class FakeEntrypoint
-{
-}
diff --git a/tests/SampleApp/Program.cs b/tests/SampleApp/Program.cs
index 83b5bb40..e455bead 100644
--- a/tests/SampleApp/Program.cs
+++ b/tests/SampleApp/Program.cs
@@ -16,3 +16,11 @@
app.MapDelete("/api/values/{id}", (string id) => Results.NoContent());
app.Run();
+
+namespace SampleApp
+{
+ public partial class Program
+ {
+ // Expose the Program class for use with WebApplicationFactory
+ }
+}
diff --git a/tests/SampleApp/SampleApp.csproj b/tests/SampleApp/SampleApp.csproj
index 1e5b7408..fe4c341b 100644
--- a/tests/SampleApp/SampleApp.csproj
+++ b/tests/SampleApp/SampleApp.csproj
@@ -1,7 +1,7 @@
false
- $(NoWarn);CA1801;CA1822;CA1861;SA1600
+ $(NoWarn);CA1801;CA1822;CA1861;SA1600;SA1601
net8.0