Skip to content

Commit e39e9bf

Browse files
Support xunit v3 (#804)
- Add support for xunit v3 via the new MartinCostello.Logging.XUnit.v3 NuGet package. - Bump version to 0.5.0. - Add a package icon (xunit's own logo).
1 parent 8eae44c commit e39e9bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2990
-2814
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ updates:
2626
- dependency-name: Microsoft.Extensions.Logging
2727
- dependency-name: xunit.abstractions
2828
- dependency-name: xunit.extensibility.execution
29+
- dependency-name: xunit.v3.extensibility.core

Directory.Build.props

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<NeutralLanguage>en-US</NeutralLanguage>
2929
<NuGetAuditMode>direct</NuGetAuditMode>
3030
<Nullable>enable</Nullable>
31-
<PackageIcon></PackageIcon>
31+
<PackageIcon>package-icon.png</PackageIcon>
3232
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
3333
<PackageProjectUrl>https://github.com/martincostello/xunit-logging</PackageProjectUrl>
3434
<PackageReadmeFile>package-readme.md</PackageReadmeFile>
@@ -44,8 +44,8 @@
4444
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
4545
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
4646
<UseArtifactsOutput>true</UseArtifactsOutput>
47-
<AssemblyVersion>0.4.0.0</AssemblyVersion>
48-
<VersionPrefix>0.4.1</VersionPrefix>
47+
<AssemblyVersion>0.5.0.0</AssemblyVersion>
48+
<VersionPrefix>0.5.0</VersionPrefix>
4949
</PropertyGroup>
5050
<PropertyGroup Condition=" '$(GITHUB_ACTIONS)' != '' ">
5151
<VersionSuffix Condition=" '$(VersionSuffix)' == '' AND '$(GITHUB_HEAD_REF)' == '' ">beta.$(GITHUB_RUN_NUMBER)</VersionSuffix>
@@ -72,10 +72,16 @@
7272
</PropertyGroup>
7373
<ItemGroup>
7474
<Using Include="System.Globalization" />
75+
<Using Include="Xunit" />
76+
<Using Include="Xunit.Sdk" />
77+
</ItemGroup>
78+
<ItemGroup Condition=" $(DefineConstants.Contains('XUNIT_V3')) ">
79+
<Using Include="Xunit.v3" />
80+
</ItemGroup>
81+
<ItemGroup Condition=" !$(DefineConstants.Contains('XUNIT_V3')) ">
82+
<Using Include="Xunit.Abstractions" />
7583
</ItemGroup>
7684
<ItemGroup Condition=" '$(IsTestProject)' == 'true' ">
7785
<Using Include="Shouldly" />
78-
<Using Include="Xunit" />
79-
<Using Include="Xunit.Abstractions" />
8086
</ItemGroup>
8187
</Project>

Directory.Packages.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
<PackageVersion Include="xunit.abstractions" Version="2.0.3" />
1717
<PackageVersion Include="xunit.extensibility.execution" Version="2.9.2" />
1818
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.0" />
19+
<PackageVersion Include="xunit.v3" Version="1.0.0" />
20+
<PackageVersion Include="xunit.v3.extensibility.core" Version="1.0.0" />
1921
</ItemGroup>
2022
<ItemGroup Condition=" '$(IsTestProject)' == 'true' ">
2123
<PackageReference Include="coverlet.msbuild" PrivateAssets="All" />

Logging.XUnit.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
6767
.github\workflows\release.yml = .github\workflows\release.yml
6868
EndProjectSection
6969
EndProject
70+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MartinCostello.Logging.XUnit.v3", "src\Logging.XUnit.v3\MartinCostello.Logging.XUnit.v3.csproj", "{2C161BB9-E6D0-4561-9D98-EDEAA8A49C5E}"
71+
EndProject
72+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MartinCostello.Logging.XUnit.v3.Tests", "tests\Logging.XUnit.v3.Tests\MartinCostello.Logging.XUnit.v3.Tests.csproj", "{828C7199-ADF2-456C-8BBB-4A73A329D017}"
73+
EndProject
7074
Global
7175
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7276
Debug|Any CPU = Debug|Any CPU
@@ -85,6 +89,14 @@ Global
8589
{B690F271-3B5D-4975-A607-AED1768595B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
8690
{B690F271-3B5D-4975-A607-AED1768595B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
8791
{B690F271-3B5D-4975-A607-AED1768595B1}.Release|Any CPU.Build.0 = Release|Any CPU
92+
{2C161BB9-E6D0-4561-9D98-EDEAA8A49C5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
93+
{2C161BB9-E6D0-4561-9D98-EDEAA8A49C5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
94+
{2C161BB9-E6D0-4561-9D98-EDEAA8A49C5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
95+
{2C161BB9-E6D0-4561-9D98-EDEAA8A49C5E}.Release|Any CPU.Build.0 = Release|Any CPU
96+
{828C7199-ADF2-456C-8BBB-4A73A329D017}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
97+
{828C7199-ADF2-456C-8BBB-4A73A329D017}.Debug|Any CPU.Build.0 = Debug|Any CPU
98+
{828C7199-ADF2-456C-8BBB-4A73A329D017}.Release|Any CPU.ActiveCfg = Release|Any CPU
99+
{828C7199-ADF2-456C-8BBB-4A73A329D017}.Release|Any CPU.Build.0 = Release|Any CPU
88100
EndGlobalSection
89101
GlobalSection(SolutionProperties) = preSolution
90102
HideSolutionNode = FALSE
@@ -97,6 +109,8 @@ Global
97109
{BB443063-F523-474D-83E3-D5FF5B075950} = {2684B19D-7D49-4099-8BD2-4D281455EB29}
98110
{B690F271-3B5D-4975-A607-AED1768595B1} = {278BCCB1-39B2-46DB-9395-7F85995A6132}
99111
{7764A046-DEE7-4D88-83E2-537DB7767123} = {D0426D09-1FF8-4E1F-A9AF-38DDEE5D7CCA}
112+
{2C161BB9-E6D0-4561-9D98-EDEAA8A49C5E} = {2684B19D-7D49-4099-8BD2-4D281455EB29}
113+
{828C7199-ADF2-456C-8BBB-4A73A329D017} = {278BCCB1-39B2-46DB-9395-7F85995A6132}
100114
EndGlobalSection
101115
GlobalSection(ExtensibilityGlobals) = postSolution
102116
SolutionGuid = {3B9E157C-5E92-4357-B233-281B4530EABD}

README.md

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,49 @@
11
# xunit Logging
22

3-
[![NuGet](https://img.shields.io/nuget/v/MartinCostello.Logging.XUnit?logo=nuget&label=Latest&color=blue)](https://www.nuget.org/packages/MartinCostello.Logging.XUnit "Download MartinCostello.Logging.XUnit from NuGet")
4-
[![NuGet Downloads](https://img.shields.io/nuget/dt/MartinCostello.Logging.XUnit?logo=nuget&label=Downloads&color=blue)](https://www.nuget.org/packages/MartinCostello.Logging.XUnit "Download MartinCostello.Logging.XUnit from NuGet")
3+
[![Build status][build-badge]][build-status]
4+
[![codecov][coverage-badge]][coverage-report]
5+
[![OpenSSF Scorecard][scorecard-badge]][scorecard-report]
56

6-
[![Build status](https://github.com/martincostello/xunit-logging/workflows/build/badge.svg?branch=main&event=push)](https://github.com/martincostello/xunit-logging/actions?query=workflow%3Abuild+branch%3Amain+event%3Apush)
7-
[![codecov](https://codecov.io/gh/martincostello/xunit-logging/branch/main/graph/badge.svg)](https://codecov.io/gh/martincostello/xunit-logging)
8-
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/martincostello/xunit-logging/badge)](https://securityscorecards.dev/viewer/?uri=github.com/martincostello/xunit-logging)
7+
| **xunit version** | **Package** | **NuGet Version** |
8+
|:------------------|:------------|:------------------|
9+
| xunit v2 | [MartinCostello.Logging.XUnit][package-download-v2] | [![NuGet][package-badge-version-v2]][package-download-v2] [![NuGet Downloads][package-badge-downloads-v2]][package-download-v2] |
10+
| xunit v3 | [MartinCostello.Logging.XUnit.v3][package-download-v3] | [![NuGet][package-badge-version-v3]][package-download-v3] [![NuGet Downloads][package-badge-downloads-v3]][package-download-v3] |
911

1012
## Introduction
1113

12-
`MartinCostello.Logging.XUnit` provides extensions to hook into the `ILogger` infrastructure to output logs from your xunit tests to the test output.
14+
`MartinCostello.Logging.XUnit` and `MartinCostello.Logging.XUnit.v3` provide extensions to hook into
15+
the `ILogger` infrastructure to output logs from your xunit tests to the test output.
16+
17+
Projects using xunit v2 should use the `MartinCostello.Logging.XUnit` package, while projects using
18+
xunit v3 should use the `MartinCostello.Logging.XUnit.v3` package.
1319

1420
> [!NOTE]
15-
> This library is designed for the Microsoft logging implementation of `ILoggerFactory`. For other logging implementations, such as [Serilog](https://serilog.net/), consider using packages such as [Serilog.Sinks.XUnit](https://github.com/trbenning/serilog-sinks-xunit) instead.
21+
> This library is designed for the Microsoft logging implementation of `ILoggerFactory`.
22+
> For other logging implementations, such as [Serilog][serilog], consider using packages such as [Serilog.Sinks.XUnit][serilog-sinks-xunit] instead.
1623
1724
### Installation
1825

19-
To install the library from [NuGet](https://www.nuget.org/packages/MartinCostello.Logging.XUnit/ "MartinCostello.Logging.XUnit on NuGet.org") using the .NET SDK run:
26+
To install the library from NuGet using the .NET SDK run one of the following commands.
27+
28+
#### For xunit v2
2029

2130
```console
2231
dotnet add package MartinCostello.Logging.XUnit
2332
```
2433

34+
#### For xunit v3
35+
36+
```console
37+
dotnet add package MartinCostello.Logging.XUnit.v3
38+
```
39+
2540
### Usage
2641

2742
```csharp
2843
using Microsoft.Extensions.DependencyInjection;
2944
using Microsoft.Extensions.Logging;
3045
using Xunit;
31-
using Xunit.Abstractions;
46+
using Xunit.Abstractions; // For xunit v2 - not required for xunit v3
3247
3348
namespace MyApp.Calculator;
3449

@@ -68,29 +83,50 @@ public sealed class Calculator(ILogger<Calculator> logger)
6883

6984
See below for links to more examples:
7085

71-
- [Unit tests](https://github.com/martincostello/xunit-logging/blob/main/tests/Logging.XUnit.Tests/Examples.cs "Unit test examples")
72-
- [Integration tests for an ASP.NET Core HTTP application](https://github.com/martincostello/xunit-logging/blob/main/tests/Logging.XUnit.Tests/Integration/HttpApplicationTests.cs "Integration test examples")
86+
- [Unit tests][example-unit-tests]
87+
- [Integration tests for an ASP.NET Core HTTP application][example-integration-tests]
7388

7489
## Feedback
7590

76-
Any feedback or issues can be added to the issues for this project in [GitHub](https://github.com/martincostello/xunit-logging/issues "Issues for this project on GitHub.com").
91+
Any feedback or issues can be added to the issues for this project in [GitHub][issues].
7792

7893
## Repository
7994

80-
The repository is hosted in [GitHub](https://github.com/martincostello/xunit-logging "This project on GitHub.com"): <https://github.com/martincostello/xunit-logging.git>
95+
The repository is hosted in [GitHub][repo]: <https://github.com/martincostello/xunit-logging.git>
8196

8297
## License
8398

84-
This project is licensed under the [Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt "The Apache 2.0 license") license.
99+
This project is licensed under the [Apache 2.0][license] license.
85100

86101
## Building and Testing
87102

88-
Compiling the library yourself requires Git and the [.NET SDK](https://www.microsoft.com/net/download/core "Download the .NET SDK") to be installed (version `9.0.100` or later).
103+
Compiling the solution yourself requires Git and the [.NET SDK][dotnet-sdk] to be installed (version `9.0.100` or later).
89104

90-
To build and test the library locally from a terminal/command-line, run one of the following set of commands:
105+
To build and test the solution locally from a terminal/command-line, run the following set of commands:
91106

92107
```powershell
93108
git clone https://github.com/martincostello/xunit-logging.git
94109
cd xunit-logging
95110
./build.ps1
96111
```
112+
113+
[build-badge]: https://github.com/martincostello/xunit-logging/actions/workflows/build.yml/badge.svg?branch=main&event=push
114+
[build-status]: https://github.com/martincostello/xunit-logging/actions?query=workflow%3Abuild+branch%3Amain+event%3Apush "Continuous Integration for this project"
115+
[coverage-badge]: https://codecov.io/gh/martincostello/xunit-logging/branch/main/graph/badge.svg
116+
[coverage-report]: https://codecov.io/gh/martincostello/xunit-logging "Code coverage report for this project"
117+
[scorecard-badge]: https://api.securityscorecards.dev/projects/github.com/martincostello/xunit-logging/badge
118+
[scorecard-report]: https://securityscorecards.dev/viewer/?uri=github.com/martincostello/xunit-logging "OpenSSF Scorecard for this project"
119+
[dotnet-sdk]: https://dot.net/download "Download the .NET SDK"
120+
[example-integration-tests]: https://github.com/martincostello/xunit-logging/blob/main/tests/Shared/Integration/HttpApplicationTests.cs "Integration test examples"
121+
[example-unit-tests]: https://github.com/martincostello/xunit-logging/blob/main/tests/Shared/Examples.cs "Unit test examples"
122+
[issues]: https://github.com/martincostello/xunit-logging/issues "Issues for this project on GitHub.com"
123+
[license]: https://www.apache.org/licenses/LICENSE-2.0.txt "The Apache 2.0 license"
124+
[package-badge-downloads-v2]: https://img.shields.io/nuget/dt/MartinCostello.Logging.XUnit?logo=nuget&label=Downloads&color=blue
125+
[package-badge-downloads-v3]: https://img.shields.io/nuget/dt/MartinCostello.Logging.XUnit.v3?logo=nuget&label=Downloads&color=blue
126+
[package-badge-version-v2]: https://img.shields.io/nuget/v/MartinCostello.Logging.XUnit?logo=nuget&label=Latest&color=blue
127+
[package-badge-version-v3]: https://img.shields.io/nuget/v/MartinCostello.Logging.XUnit.v3?logo=nuget&label=Latest&color=blue
128+
[package-download-v2]: https://www.nuget.org/packages/MartinCostello.Logging.XUnit "Download MartinCostello.Logging.XUnit from NuGet"
129+
[package-download-v3]: https://www.nuget.org/packages/MartinCostello.Logging.XUnit.v3 "Download MartinCostello.Logging.XUnit.v3 from NuGet"
130+
[repo]: https://github.com/martincostello/xunit-loggingE "This project on GitHub.com"
131+
[serilog]: https://serilog.net/ "Serilog website"
132+
[serilog-sinks-xunit]: https://github.com/trbenning/serilog-sinks-xunit "Serilog.Sinks.XUnit on GitHub"

build.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ $ProgressPreference = "SilentlyContinue"
1414
$solutionPath = $PSScriptRoot
1515
$sdkFile = Join-Path $solutionPath "global.json"
1616

17-
$libraryProject = Join-Path $solutionPath "src" "Logging.XUnit" "MartinCostello.Logging.XUnit.csproj"
17+
$libraryProjects = @(
18+
(Join-Path $solutionPath "src" "Logging.XUnit" "MartinCostello.Logging.XUnit.csproj")
19+
(Join-Path $solutionPath "src" "Logging.XUnit.v3" "MartinCostello.Logging.XUnit.v3.csproj")
20+
)
1821

1922
$testProjects = @(
2023
(Join-Path $solutionPath "tests" "Logging.XUnit.Tests" "MartinCostello.Logging.XUnit.Tests.csproj")
24+
(Join-Path $solutionPath "tests" "Logging.XUnit.v3.Tests" "MartinCostello.Logging.XUnit.v3.Tests.csproj")
2125
)
2226

2327
$dotnetVersion = (Get-Content $sdkFile | Out-String | ConvertFrom-Json).sdk.version
@@ -102,8 +106,10 @@ function DotNetTest {
102106
}
103107
}
104108

105-
Write-Information "Packaging library..."
106-
DotNetPack $libraryProject
109+
Write-Information "Packaging libraries..."
110+
ForEach ($libraryProject in $libraryProjects) {
111+
DotNetPack $libraryProject
112+
}
107113

108114
if (-Not $SkipTests) {
109115
Write-Information "Running tests..."

package-icon.png

1001 Bytes
Loading

package-readme.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
## Introduction
44

5-
`MartinCostello.Logging.XUnit` provides extensions to hook into the `ILogger` infrastructure to output logs from your xunit tests to the test output.
5+
`MartinCostello.Logging.XUnit` and `MartinCostello.Logging.XUnit.v3` provide extensions to hook
6+
into the `ILogger` infrastructure to output logs from your xunit tests to the test output.
67

78
### Usage
89

910
```csharp
1011
using Microsoft.Extensions.DependencyInjection;
1112
using Microsoft.Extensions.Logging;
1213
using Xunit;
13-
using Xunit.Abstractions;
14+
using Xunit.Abstractions; // For xunit v2 - not required for xunit v3
1415
1516
namespace MyApp.Calculator;
1617

@@ -50,8 +51,11 @@ public sealed class Calculator(ILogger<Calculator> logger)
5051

5152
## Feedback
5253

53-
Any feedback or issues can be added to the issues for this project in [GitHub](https://github.com/martincostello/xunit-logging/issues "Issues for this project on GitHub.com").
54+
Any feedback or issues can be added to the issues for this project in [GitHub][issues].
5455

5556
## License
5657

57-
This project is licensed under the [Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt "The Apache 2.0 license") license.
58+
This project is licensed under the [Apache 2.0][license] license.
59+
60+
[issues]: https://github.com/martincostello/xunit-logging/issues "Issues for this package on GitHub.com"
61+
[license]: https://www.apache.org/licenses/LICENSE-2.0.txt "The Apache 2.0 license"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<AssemblyTitle>Logging Extensions for xunit v3</AssemblyTitle>
4+
<DefineConstants>$(DefineConstants);XUNIT_V3</DefineConstants>
5+
<Description>Extensions for Microsoft.Extensions.Logging for xunit v3.</Description>
6+
<EnablePackageValidation>true</EnablePackageValidation>
7+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
8+
<IsPackable>true</IsPackable>
9+
<OutputType>Library</OutputType>
10+
<PackageId>MartinCostello.Logging.XUnit.v3</PackageId>
11+
<!--
12+
<PackageValidationBaselineVersion>0.5.0</PackageValidationBaselineVersion>
13+
-->
14+
<RootNamespace>MartinCostello.Logging.XUnit</RootNamespace>
15+
<Summary>$(Description)</Summary>
16+
<TargetFrameworks>net8.0;net472</TargetFrameworks>
17+
<Title>xunit v3 Logging Extensions</Title>
18+
</PropertyGroup>
19+
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
20+
<IsAotCompatible>true</IsAotCompatible>
21+
</PropertyGroup>
22+
<ItemGroup>
23+
<Compile Include="..\Shared\**\*.cs" Link="%(Link)" />
24+
</ItemGroup>
25+
<ItemGroup>
26+
<PackageReference Include="Microsoft.Extensions.Logging" VersionOverride="8.0.1" />
27+
<PackageReference Include="xunit.v3.extensibility.core" />
28+
</ItemGroup>
29+
<ItemGroup>
30+
<AssemblyAttribute Include="System.Runtime.InteropServices.GuidAttribute">
31+
<_Parameter1>ed8d1c5e-3ee7-45fe-8d1d-94257a71f02a</_Parameter1>
32+
</AssemblyAttribute>
33+
<InternalsVisibleTo Include="MartinCostello.Logging.XUnit.v3.Tests" PublicKey="$(StrongNamePublicKey)" />
34+
</ItemGroup>
35+
</Project>

src/Logging.XUnit/CompatibilitySuppressions.xml

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)