Serilog.Sinks.XUnit.Injectable 4.0.256

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

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Serilog.Sinks.XUnit.Injectable

A Serilog sink whose active xUnit ITestOutputHelper can be replaced for each test while the logger and test fixture remain shared.

Installation

dotnet add package Serilog.Sinks.XUnit.Injectable

Configure the shared fixture

Create one sink for the lifetime of the shared service provider or WebApplicationFactory, register that same instance in DI, and pass it to Serilog:

using Serilog;
using Serilog.Sinks.XUnit.Injectable;
using Serilog.Sinks.XUnit.Injectable.Abstract;
using Serilog.Sinks.XUnit.Injectable.Extensions;

var outputSink = new InjectableTestOutputSink(
    outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{Exception}");

services.AddSingleton<IInjectableTestOutputSink>(outputSink);

Log.Logger = new LoggerConfiguration()
    .WriteTo.InjectableTestOutput(outputSink)
    .CreateLogger();

The sink must be the same instance used by the shared logger. Creating a new sink for each test will not redirect logs already produced by services in the fixture.

Inject each test's output helper

Inject the helper before the test starts work:

public sealed class ApiTests
{
    private readonly HttpClient _client;

    public ApiTests(ApiFixture fixture, ITestOutputHelper output)
    {
        IInjectableTestOutputSink sink =
            fixture.Services.GetRequiredService<IInjectableTestOutputSink>();

        sink.Inject(output);
        _client = fixture.CreateClient();
    }

    [Fact]
    public async Task Get_returns_success()
    {
        using HttpResponseMessage response = await _client.GetAsync("/");
        response.EnsureSuccessStatusCode();
    }
}

Calling Inject replaces the helper and optional diagnostic message sink used for subsequent writes. Tests sharing this sink should not run concurrently: a later injection can redirect queued output from another test.

Events received before a helper is available are buffered and written when a helper is injected. If xUnit rejects a write because that test has ended, the sink clears the helper and retains that event for the next injection.

Capacity and disposal

Logging never blocks producers. The sink uses a bounded 4,096-event channel and retains at most 2,048 events while no helper is available. Events beyond either capacity are silently dropped, so this is test-output plumbing rather than durable log storage.

Dispose or flush the Serilog logger during fixture teardown. Dispose and DisposeAsync are idempotent; asynchronous disposal allows up to two seconds for a normal drain before cancellation. Complete() stops accepting events early and is normally unnecessary when the logger owns the sink.

An optional xUnit IMessageSink can be supplied alongside the helper:

sink.Inject(output, diagnosticMessageSink);

Formatted events are sent to both destinations while a helper is active.

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Serilog.Sinks.XUnit.Injectable:

Package Downloads
Soenneker.Fixtures.Unit

A base xUnit fixture providing injectable log output, DI mechanisms like IServiceCollection and ServiceProvider, and AutoFaker/Faker for generating test data.

Soenneker.Fixtures.Integration

Provides a reusable and generic integration test xunit fixture that dynamically registers and configures WebApplicationFactory instances for multiple ASP.NET Core projects with support for custom app settings, authentication, logging, and test utilities.

DotCart.Drivers.Serilog

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.256 67 8/30/2026
4.0.254 48 8/30/2026
4.0.253 84 8/30/2026
4.0.252 118 8/30/2026
4.0.251 70 8/30/2026
4.0.250 66 8/29/2026
4.0.249 90 8/29/2026
4.0.247 1,310 8/15/2026
4.0.246 2,831 7/28/2026
4.0.245 153 7/28/2026
4.0.244 286 7/28/2026
4.0.243 109 7/28/2026
4.0.242 203 7/27/2026
4.0.241 2,927 7/18/2026
4.0.240 342 7/17/2026
4.0.239 128 7/17/2026
4.0.238 285 7/16/2026
4.0.237 338 7/16/2026
4.0.235 939 7/10/2026
4.0.234 3,997 6/19/2026
Loading failed