Serilog.Sinks.XUnit.Injectable
4.0.254
See the version list below for details.
dotnet add package Serilog.Sinks.XUnit.Injectable --version 4.0.254
NuGet\Install-Package Serilog.Sinks.XUnit.Injectable -Version 4.0.254
<PackageReference Include="Serilog.Sinks.XUnit.Injectable" Version="4.0.254" />
<PackageVersion Include="Serilog.Sinks.XUnit.Injectable" Version="4.0.254" />
<PackageReference Include="Serilog.Sinks.XUnit.Injectable" />
paket add Serilog.Sinks.XUnit.Injectable --version 4.0.254
#r "nuget: Serilog.Sinks.XUnit.Injectable, 4.0.254"
#:package Serilog.Sinks.XUnit.Injectable@4.0.254
#addin nuget:?package=Serilog.Sinks.XUnit.Injectable&version=4.0.254
#tool nuget:?package=Serilog.Sinks.XUnit.Injectable&version=4.0.254
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 | Versions 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. |
-
net10.0
- Serilog (>= 4.4.0)
- Soenneker.Atomics.ValueBools (>= 4.0.38)
- Soenneker.Extensions.Task (>= 4.0.128)
- Soenneker.Extensions.ValueTask (>= 4.0.119)
- Soenneker.Utils.ReusableStringWriter (>= 4.0.25)
- xunit.v3.extensibility.core (>= 4.0.0)
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 | 151 | 8/30/2026 |
| 4.0.254 | 65 | 8/30/2026 |
| 4.0.253 | 110 | 8/30/2026 |
| 4.0.252 | 136 | 8/30/2026 |
| 4.0.251 | 87 | 8/30/2026 |
| 4.0.250 | 80 | 8/29/2026 |
| 4.0.249 | 104 | 8/29/2026 |
| 4.0.247 | 1,326 | 8/15/2026 |
| 4.0.246 | 2,910 | 7/28/2026 |
| 4.0.245 | 159 | 7/28/2026 |
| 4.0.244 | 289 | 7/28/2026 |
| 4.0.243 | 111 | 7/28/2026 |
| 4.0.242 | 206 | 7/27/2026 |
| 4.0.241 | 3,022 | 7/18/2026 |
| 4.0.240 | 345 | 7/17/2026 |
| 4.0.239 | 130 | 7/17/2026 |
| 4.0.238 | 287 | 7/16/2026 |
| 4.0.237 | 340 | 7/16/2026 |
| 4.0.235 | 941 | 7/10/2026 |
| 4.0.234 | 4,018 | 6/19/2026 |