Stravaig.Extensions.Logging.Diagnostics 3.0.3

dotnet add package Stravaig.Extensions.Logging.Diagnostics --version 3.0.3
                    
NuGet\Install-Package Stravaig.Extensions.Logging.Diagnostics -Version 3.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Stravaig.Extensions.Logging.Diagnostics" Version="3.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Stravaig.Extensions.Logging.Diagnostics" Version="3.0.3" />
                    
Directory.Packages.props
<PackageReference Include="Stravaig.Extensions.Logging.Diagnostics" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Stravaig.Extensions.Logging.Diagnostics --version 3.0.3
                    
#r "nuget: Stravaig.Extensions.Logging.Diagnostics, 3.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Stravaig.Extensions.Logging.Diagnostics@3.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Stravaig.Extensions.Logging.Diagnostics&version=3.0.3
                    
Install as a Cake Addin
#tool nuget:?package=Stravaig.Extensions.Logging.Diagnostics&version=3.0.3
                    
Install as a Cake Tool

About

Stravaig Log Capture is a way to capture the logs in a test and examine them to ensure they are being generated correctly.

Version & Framework support

  • v1.x: Supports .NET Core 3.1 & .NET 5
  • v2.x: Supports .NET 6.0, 7.0 & 8.0
  • v3.x: Supports .NET 6.0, 8.0 & 9.0

Why do I want to test my logs?

Checking logs in test can be beneficial for a number of reasons. For example, in a background service the log is effectively its user interface (the user being the developer or system admin whose job it is to monitor the correct running of background services). By verifying the logs in tests, you can ensure that appropriate information is being delivered.

Logging may also exist to output audit trails for the application, and you need to check in tests that it is being produced correctly.

How to use

For simple tests you can pass the logger into the class under test like this:

[Test]
public void EnsureSomeFunctionalityWorks()
{
    // Arrange
    var logger = new TestCaptureLogger<ServiceClass>();
    var service = new ServiceClass(logger);
    
    // Act
    service.DoSomething();
    
    // Assert
    var logs = logger.GetLogs();
    logs.Count.ShouldBe(1);
    logs[0].OriginalMessage.ShouldBe("Did something.");
}

See also

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Stravaig.Extensions.Logging.Diagnostics:

Package Downloads
Stravaig.Extensions.Logging.Diagnostics.XUnit

XUnit extensions for Stravaig Logging Capture for Tests. Use version 2.x for .NET 6.0 onwards. Use version 3.x for .NET 6.0, 8.0 & 9.0 onwards.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.3 5,124 3/13/2025
3.0.3-preview.1 128 3/12/2025
3.0.2 247 2/24/2025
3.0.2-preview.1 70 2/23/2025
3.0.1 3,781 12/1/2024
3.0.0-preview.466 66 11/23/2024
3.0.0-preview.463 71 11/16/2024
3.0.0-preview.455 67 11/3/2024
2.2.1 12,889 2/27/2024
2.2.0 2,426 11/15/2023
2.2.0-preview.383 94 11/15/2023
2.1.0 4,163 7/31/2023
2.1.0-preview.356 139 7/30/2023
2.0.1 1,103 6/13/2023
2.0.0 818 2/11/2023
2.0.0-preview.305 146 12/11/2022
1.4.1 1,133 12/6/2022
1.4.0 750 11/13/2022
1.3.3 1,054 9/14/2022
1.3.2 1,142 8/9/2022
1.3.2-preview.267 170 8/9/2022
1.3.1 529 8/6/2022
1.3.1-preview.263 166 8/6/2022
1.3.0 1,473 5/23/2022
1.2.3 803 5/11/2022
1.2.2 1,025 4/12/2022
1.2.1 979 3/9/2022
1.2.0 1,313 2/6/2022
1.2.0-preview.227 215 12/20/2021
1.2.0-preview.212 311 11/13/2021
1.1.4 1,305 11/13/2021
1.1.3 864 10/12/2021
1.1.2 730 9/14/2021
1.1.1 741 8/11/2021
1.1.0 666 7/30/2021
1.0.1 803 7/14/2021
1.0.0 964 6/19/2021
0.4.4-preview.160 277 6/19/2021
0.4.3 559 6/9/2021
0.4.2 791 5/15/2021
0.4.1 1,003 4/12/2021
0.4.0 848 3/20/2021
0.4.0-preview.123 298 3/19/2021
0.3.2 1,041 2/11/2021
0.3.1 1,487 1/13/2021
0.3.0 957 12/14/2020
0.2.2 768 11/22/2020
0.2.1 715 10/25/2020
0.2.0 582 10/20/2020
0.1.0 757 10/8/2020
0.0.3-preview.37 340 10/7/2020