File tree Expand file tree Collapse file tree 3 files changed +56
-5
lines changed
src/Stravaig.Extensions.Logging.Diagnostics Expand file tree Collapse file tree 3 files changed +56
-5
lines changed Original file line number Diff line number Diff line change 33<!--
44Thank you for taking the time to contribute to this project.
55
6- Please, fill in all the sections.
6+ Please, fill in all the sections.
77Replace items surrounded by chevrons appropriately.
88-->
99
@@ -23,13 +23,14 @@ This PR addresses Issue #<issue-number>.
2323
2424### Optional
2525
26- <!--
26+ <!--
2727Depending on what the PR is for these may not be needed.
2828If any of these items are not needed, then they can be removed.
2929-->
3030
31- - [ ] I have updated the `readme.md` file
31+ - [ ] I have updated the repo `readme.md` file.
32+ - [ ] I have updated the package `readme.md` file.
3233- [ ] I have updated the documentation in the docs folder.
33- - [ ] I have bumped the version number in the `version.txt`
34+ - [ ] I have bumped the version number in the `version.txt`.
3435- [ ] I have added or updated any necessary tests.
35- - [ ] I have ensured that any new code is covered by tests where reasonably possible.
36+ - [ ] I have ensured that any new code is covered by tests where reasonably possible.
Original file line number Diff line number Diff line change 1212 <PackageIcon >stravaig-icon.png</PackageIcon >
1313 <PackageTags >logging testing</PackageTags >
1414 <GenerateDocumentationFile >true</GenerateDocumentationFile >
15+ <PackageReadmeFile >readme.md</PackageReadmeFile >
1516 <Description >
1617 A logging provider that hooks into the .NET Logging extensions and captures
1718 the logs that it receives so they can be examined later by tests.
3637 <ContinuousIntegrationBuild >true</ContinuousIntegrationBuild >
3738 </PropertyGroup >
3839
40+ <ItemGroup >
41+ <None Include =" readme.md" Pack =" True" PackagePath =" /" />
42+ </ItemGroup >
43+
3944 <ItemGroup >
4045 <PackageReference Include =" Microsoft.SourceLink.GitHub" Version =" 8.0.0" PrivateAssets =" All" />
4146 </ItemGroup >
Original file line number Diff line number Diff line change 1+ # About
2+
3+ Stravaig Log Capture is a way to capture the logs in a test and examine them to ensure they are being generated correctly.
4+
5+ ## Version & Framework support
6+
7+ * v1.x: Supports .NET Core 3.1 & .NET 5
8+ * v2.x: Supports .NET 6.0, 7.0 & 8.0
9+ * v3.x: Supports .NET 6.0 & 8.0
10+
11+ ## Why do I want to test my logs?
12+
13+ Checking logs in test can be beneficial for a number of reasons.
14+ For example, in a background service the log is effectively its user
15+ interface (the user being the developer or system admin whose job it
16+ is to monitor the correct running of background services). By verifying
17+ the logs in tests, you can ensure that appropriate information is being
18+ delivered.
19+
20+ Logging may also exist to output audit trails for the application, and you
21+ need to check in tests that it is being produced correctly.
22+
23+ ## How to use
24+
25+ For simple tests you can pass the logger into the class under test like this:
26+
27+ ``` csharp
28+ [Test ]
29+ public void EnsureSomeFunctionalityWorks ()
30+ {
31+ // Arrange
32+ var logger = new TestCaptureLogger <ServiceClass >();
33+ var service = new ServiceClass (logger );
34+
35+ // Act
36+ service .DoSomething ();
37+
38+ // Assert
39+ var logs = logger .GetLogs ();
40+ logs .Count .ShouldBe (1 );
41+ logs [0 ].OriginalMessage .ShouldBe (" Did something." );
42+ }
43+ ```
44+
45+ For more details on more complex scenarios, see the full documentation at https://stravaig-projects.github.io/Stravaig.Extensions.Logging.Diagnostics/
You can’t perform that action at this time.
0 commit comments