Serilog.Sinks.TestCorrelator 4.0.2

dotnet add package Serilog.Sinks.TestCorrelator --version 4.0.2
                    
NuGet\Install-Package Serilog.Sinks.TestCorrelator -Version 4.0.2
                    
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="Serilog.Sinks.TestCorrelator" Version="4.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Serilog.Sinks.TestCorrelator" Version="4.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Serilog.Sinks.TestCorrelator" />
                    
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 Serilog.Sinks.TestCorrelator --version 4.0.2
                    
#r "nuget: Serilog.Sinks.TestCorrelator, 4.0.2"
                    
#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 Serilog.Sinks.TestCorrelator@4.0.2
                    
#: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=Serilog.Sinks.TestCorrelator&version=4.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Serilog.Sinks.TestCorrelator&version=4.0.2
                    
Install as a Cake Tool

Serilog.Sinks.TestCorrelator CI Build NuGet Version NuGet Downloads

A Serilog sink that correlates log events with the code that produced them, enabling unit testing of log output.

Usage

Just create a logger that writes or audits to the TestCorrelator.

Log.Logger = new LoggerConfiguration().WriteTo.TestCorrelator().CreateLogger();

Then wrap the code that you would like to monitor with a context and get the log events emitted within that context using the TestCorrelator.

using (TestCorrelator.CreateContext())
{
    Log.Information("My log message!");

    TestCorrelator.GetLogEventsFromCurrentContext()
        .Should().ContainSingle()
        .Which.MessageTemplate.Text
        .Should().Be("My log message!");
}

You can also get a stream of log events as an observable, which can be useful for testing long running or asynchronous tasks.

using (TestCorrelator.CreateContext())
{
    TestCorrelator.GetLogEventStreamFromCurrentContext()
        .Subscribe(logEvent => logEvent.MessageTemplate.Text.Should().Be("My log message!"));

    Log.Information("My log message!");
}

New in v4: If you have more than one logger and want to filter to only log events emitted to a specific sink you can pass in an ID that you then use to filter the log events.

TestCorrelatorSinkId firstTestCorrelatorSinkId = new();
ILogger firstLogger = new LoggerConfiguration().WriteTo.TestCorrelator(firstTestCorrelatorSinkId).CreateLogger();

TestCorrelatorSinkId secondTestCorrelatorSinkId = new();
ILogger secondLogger = new LoggerConfiguration().WriteTo.TestCorrelator(secondTestCorrelatorSinkId).CreateLogger();

using (TestCorrelator.CreateContext())
{
    firstLogger.Information("My first log message!");
    secondLogger.Information("My second log message!");

    TestCorrelator.GetLogEventsForSinksFromCurrentContext(firstTestCorrelatorSinkId)
        .Should().ContainSingle()
        .Which.MessageTemplate.Text
        .Should().Be("My first log message!");

    TestCorrelator.GetLogEventsForSinksFromCurrentContext(secondTestCorrelatorSinkId)
        .Should().ContainSingle()
        .Which.MessageTemplate.Text
        .Should().Be("My second log message!");
}

For more examples check out the unit tests!

v4 Breaking Changes

Version 4 comes with a few breaking changes.

  • All package dependencies have been updated.
  • Dropped support for .Net Framework 4.6.1 and below. This brings the package in line with Serilog's supported frameworks.
  • A new TestCorrelatorContextId class replaces Guids. The corresponding ...ContextGuid() methods have been renamed to ...ContextId().
  • LogEvents emitted outside of a context are no longer captured.
  • LoggerConfiguration extension methods with implicitly ignored minimum LogEventLevel parameters were removed.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  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 is compatible.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 is compatible.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on Serilog.Sinks.TestCorrelator:

Package Downloads
CUSTIS.NetCore.Tests

Утилиты для тестов

PureActive.Serilog.Sink.Xunit

PureActive Serilog Sink for xUnit

OutWit.Common.Logging

Logging aspect support for MVVM

Rdh.TestHelper

Helper for Unit tests

Base.Logging

A logging utility that sanitizes JSON data to redact sensitive information.

GitHub repositories (4)

Showing the top 4 popular GitHub repositories that depend on Serilog.Sinks.TestCorrelator:

Repository Stars
BrighterCommand/Brighter
A framework for building messaging apps with .NET and C#.
Reaparr/Reaparr
Plex downloader that brings content from any server to yours!
planetarium/libplanet
Blockchain in C#/.NET for on-chain, decentralized gaming
dougdellolio/coinbasepro-csharp
The unofficial .NET/C# client library for the Coinbase Pro/GDAX API
Version Downloads Last Updated
4.0.2 913 8/27/2026
4.0.1 233 8/27/2026
4.0.0 4,744,448 6/4/2024
3.2.0 8,083,089 4/2/2019
3.1.0 66,797 1/19/2019
3.0.3 226,879 4/6/2018
3.0.2 18,665 12/14/2017
3.0.1 8,087 11/19/2017
3.0.0.68 12,425 8/18/2017
3.0.0.65 3,690 8/17/2017
3.0.0.64 36,244 8/17/2017