|
1 | 1 | # xunit Logging |
2 | 2 |
|
3 | | -[](https://www.nuget.org/packages/MartinCostello.Logging.XUnit "Download MartinCostello.Logging.XUnit from NuGet") |
4 | | -[](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] |
5 | 6 |
|
6 | | -[](https://github.com/martincostello/xunit-logging/actions?query=workflow%3Abuild+branch%3Amain+event%3Apush) |
7 | | -[](https://codecov.io/gh/martincostello/xunit-logging) |
8 | | -[](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] | |
9 | 11 |
|
10 | 12 | ## Introduction |
11 | 13 |
|
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. |
13 | 19 |
|
14 | 20 | > [!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. |
16 | 23 |
|
17 | 24 | ### Installation |
18 | 25 |
|
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 |
20 | 29 |
|
21 | 30 | ```console |
22 | 31 | dotnet add package MartinCostello.Logging.XUnit |
23 | 32 | ``` |
24 | 33 |
|
| 34 | +#### For xunit v3 |
| 35 | + |
| 36 | +```console |
| 37 | +dotnet add package MartinCostello.Logging.XUnit.v3 |
| 38 | +``` |
| 39 | + |
25 | 40 | ### Usage |
26 | 41 |
|
27 | 42 | ```csharp |
28 | 43 | using Microsoft.Extensions.DependencyInjection; |
29 | 44 | using Microsoft.Extensions.Logging; |
30 | 45 | using Xunit; |
31 | | -using Xunit.Abstractions; |
| 46 | +using Xunit.Abstractions; // For xunit v2 - not required for xunit v3 |
32 | 47 |
|
33 | 48 | namespace MyApp.Calculator; |
34 | 49 |
|
@@ -68,29 +83,50 @@ public sealed class Calculator(ILogger<Calculator> logger) |
68 | 83 |
|
69 | 84 | See below for links to more examples: |
70 | 85 |
|
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] |
73 | 88 |
|
74 | 89 | ## Feedback |
75 | 90 |
|
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]. |
77 | 92 |
|
78 | 93 | ## Repository |
79 | 94 |
|
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> |
81 | 96 |
|
82 | 97 | ## License |
83 | 98 |
|
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. |
85 | 100 |
|
86 | 101 | ## Building and Testing |
87 | 102 |
|
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). |
89 | 104 |
|
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: |
91 | 106 |
|
92 | 107 | ```powershell |
93 | 108 | git clone https://github.com/martincostello/xunit-logging.git |
94 | 109 | cd xunit-logging |
95 | 110 | ./build.ps1 |
96 | 111 | ``` |
| 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" |
0 commit comments