Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
7 changes: 3 additions & 4 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
name: Bug report
about: Create a bug report to help us improve the library
labels: bug

---

### Describe the bug
Expand Down Expand Up @@ -32,11 +31,11 @@ A clear and concise description of what actually happened. If an exception occur
### System information

<!--
- OS: [e.g. Windows 10]
- Library Version [e.g. 0.2.1]
- OS: [e.g. Windows 11]
- Library Version [e.g. 0.4.0]
- xunit version [e.g. 2.4.0]
- .NET version (e.g. output from `dotnet --info`)
- IDE and version [e.g. Visual Studio 17.2.0]
- IDE and version [e.g. Visual Studio 17.8.0]
-->

### Additional context
Expand Down
4 changes: 4 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -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.
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<UseArtifactsOutput>true</UseArtifactsOutput>
<AssemblyVersion>0.3.0.0</AssemblyVersion>
<VersionPrefix>0.3.1</VersionPrefix>
<AssemblyVersion>0.4.0.0</AssemblyVersion>
<VersionPrefix>0.4.0</VersionPrefix>
<VersionSuffix Condition=" '$(VersionSuffix)' == '' AND '$(GITHUB_ACTIONS)' != '' ">beta$([System.Convert]::ToInt32(`$(GITHUB_RUN_NUMBER)`).ToString(`0000`))</VersionSuffix>
<VersionPrefix Condition=" $(GITHUB_REF.StartsWith(`refs/tags/v`)) ">$(GITHUB_REF.Replace('refs/tags/v', ''))</VersionPrefix>
<VersionSuffix Condition=" $(GITHUB_REF.StartsWith(`refs/tags/v`)) "></VersionSuffix>
Expand Down
11 changes: 9 additions & 2 deletions Logging.XUnit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/Logging.XUnit/IMessageSinkExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ public static class IMessageSinkExtensions
/// </exception>
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);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Logging.XUnit/ITestOutputHelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ public static class ITestOutputHelperExtensions
/// </exception>
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);
}
Expand Down
16 changes: 11 additions & 5 deletions src/Logging.XUnit/MartinCostello.Logging.XUnit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,29 @@
<Description>Extensions for Microsoft.Extensions.Logging for xunit.</Description>
<EnablePackageValidation>true</EnablePackageValidation>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn)</NoWarn>
<OutputType>Library</OutputType>
<PackageId>MartinCostello.Logging.XUnit</PackageId>
<PackageValidationBaselineVersion>0.2.0</PackageValidationBaselineVersion>
<PackageValidationBaselineVersion>0.3.0</PackageValidationBaselineVersion>
<RootNamespace>MartinCostello.Logging.XUnit</RootNamespace>
<Summary>$(Description)</Summary>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
<Title>xunit Logging Extensions</Title>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugSymbols>True</DebugSymbols>
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
<EnableAotAnalyzer>true</EnableAotAnalyzer>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<IsAotCompatible>true</IsAotCompatible>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="xunit.abstractions" />
<PackageReference Include="xunit.extensibility.execution" />
</ItemGroup>
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
<PackageReference Update="Microsoft.Extensions.Logging" VersionOverride="8.0.0" />
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.InteropServices.GuidAttribute">
<_Parameter1>af808007-f06a-410b-886d-152b3f39c43f</_Parameter1>
Expand Down
2 changes: 1 addition & 1 deletion src/Logging.XUnit/XUnitLogScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal static XUnitLogScope? Current
internal XUnitLogScope? Parent { get; private set; }

/// <inheritdoc />
public override string ToString()
public override string? ToString()
=> State.ToString();

/// <summary>
Expand Down
17 changes: 13 additions & 4 deletions src/Logging.XUnit/XUnitLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -89,12 +89,17 @@ private XUnitLogger(string name, XUnitLoggerOptions? options)
internal Func<DateTimeOffset> Clock { get; set; } = static () => DateTimeOffset.Now;

/// <inheritdoc />
public IDisposable BeginScope<TState>(TState state)
public IDisposable? BeginScope<TState>(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);
}
Expand All @@ -111,17 +116,21 @@ public bool IsEnabled(LogLevel logLevel)
}

/// <inheritdoc />
public void Log<TState>(LogLevel logLevel, EventId eventId, TState? state, Exception? exception, Func<TState?, Exception?, string?> formatter)
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> 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);

Expand Down Expand Up @@ -283,7 +292,7 @@ private static void GetScopeInformation(StringBuilder builder)
/// </summary>
/// <param name="scope">The <see cref="XUnitLogScope"/> to stringify.</param>
/// <returns>An enumeration of scope properties from the current scope.</returns>
private static IEnumerable<string> StringifyScope(XUnitLogScope scope)
private static IEnumerable<string?> StringifyScope(XUnitLogScope scope)
{
if (scope.State is IEnumerable<KeyValuePair<string, object>> pairs)
{
Expand Down
Loading