Skip to content

Commit 54d507f

Browse files
Add dedicated package README
- Add a dedicated package README to improve rendering in the NuGet gallery. - Fix markdownlint warnings.
1 parent 82e80d0 commit 54d507f

File tree

3 files changed

+63
-5
lines changed

3 files changed

+63
-5
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<PackageIcon></PackageIcon>
3232
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
3333
<PackageProjectUrl>https://github.com/martincostello/xunit-logging</PackageProjectUrl>
34-
<PackageReadmeFile>README.md</PackageReadmeFile>
34+
<PackageReadmeFile>package-readme.md</PackageReadmeFile>
3535
<PackageReleaseNotes>See $(PackageProjectUrl)/releases for details.</PackageReleaseNotes>
3636
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
3737
<PackageTags>xunit;logging</PackageTags>

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
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:
1818

19-
```
19+
```console
2020
dotnet add package MartinCostello.Logging.XUnit
2121
```
2222

@@ -65,16 +65,17 @@ public sealed class Calculator(ILogger<Calculator> logger)
6565
```
6666

6767
See below for links to more examples:
68-
1. [Unit tests](https://github.com/martincostello/xunit-logging/blob/main/tests/Logging.XUnit.Tests/Examples.cs "Unit test examples")
69-
1. [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")
68+
69+
- [Unit tests](https://github.com/martincostello/xunit-logging/blob/main/tests/Logging.XUnit.Tests/Examples.cs "Unit test examples")
70+
- [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")
7071

7172
## Feedback
7273

7374
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").
7475

7576
## Repository
7677

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

7980
## License
8081

package-readme.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# xunit Logging
2+
3+
## Introduction
4+
5+
`MartinCostello.Logging.XUnit` provides extensions to hook into the `ILogger` infrastructure to output logs from your xunit tests to the test output.
6+
7+
### Usage
8+
9+
```csharp
10+
using Microsoft.Extensions.DependencyInjection;
11+
using Microsoft.Extensions.Logging;
12+
using Xunit;
13+
using Xunit.Abstractions;
14+
15+
namespace MyApp.Calculator;
16+
17+
public class CalculatorTests(ITestOutputHelper outputHelper)
18+
{
19+
[Fact]
20+
public void Calculator_Sums_Two_Integers()
21+
{
22+
// Arrange
23+
using var serviceProvider = new ServiceCollection()
24+
.AddLogging((builder) => builder.AddXUnit(outputHelper))
25+
.AddSingleton<Calculator>()
26+
.BuildServiceProvider();
27+
28+
var calculator = services.GetRequiredService<Calculator>();
29+
30+
// Act
31+
int actual = calculator.Sum(1, 2);
32+
33+
// Assert
34+
Assert.AreEqual(3, actual);
35+
}
36+
}
37+
38+
public sealed class Calculator(ILogger<Calculator> logger)
39+
{
40+
public int Sum(int x, int y)
41+
{
42+
int sum = x + y;
43+
44+
logger.LogInformation("The sum of {x} and {y} is {sum}.", x, y, sum);
45+
46+
return sum;
47+
}
48+
}
49+
```
50+
51+
## Feedback
52+
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+
55+
## License
56+
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.

0 commit comments

Comments
 (0)