Serilog.Sinks.XUnit3 1.0.0

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

alternate text is missing from this package README image

serilog-sinks-xunit-v3

The xUnit.v3 injectable test output sink for Serilog

What is it?

It's a package that will allow you to use Serilog for test output in xUnit.v3.

Installation

dotnet CLI:

dotnet add package Serilog.Sinks.XUnit3

Package Reference:

<PackageReference Include="Serilog.Sinks.XUnit3" Version="1.0.0" />

Example usage

In Unit tests you can do not think about ITestOutputHelper, as it is backed by xUnit.v3 TestContext.Current.TestOutputHelper property. This implicit behaviour will not work with Integration ones due to TestHost being run in Background Thread.

Unit tests

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace Serilog.Sinks.XUnit3.Tests.Unit;

public class UnitTestsOne
{
    [Fact]
    public void Do_Always_Success()
    {
        using var serviceProvider = new ServiceCollection()
            .AddLogging(x => x.ClearProviders()
                .AddSerilog(new LoggerConfiguration().WriteTo
                    .XUnit3TestOutput()
                    .CreateLogger()))
            .BuildServiceProvider();
        var logger = serviceProvider.GetRequiredService<ILogger<object>>();
        logger.LogInformation("Do");
    }
}

Integration tests

using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.Net.Http.Json;

namespace Serilog.Sinks.XUnit3.Tests.Integration;

[CollectionDefinition(nameof(SampleCollection))]
public class SampleCollection : ICollectionFixture<SampleFixture>;

public class SampleFixture : IAsyncLifetime
{
    public SampleFactory Factory { get; private set; } = null!;

    public SampleFixture SetTestOutputHelper(ITestOutputHelper testOutputHelper)
    {
        Factory.SetTestOutputHelper(testOutputHelper);
        return this;
    }

    public ValueTask InitializeAsync()
    {
        Factory = new SampleFactory();
        return ValueTask.CompletedTask;
    }

    public async ValueTask DisposeAsync() => await Factory.DisposeAsync();
}

public class SampleFactory : WebApplicationFactory<Program>
{
    protected override IHost CreateHost(IHostBuilder builder)
    {
        builder.ConfigureServices(services => services.AddSingleton(new XUnit3TestOutputSink()));
        builder.UseSerilog((_, serviceProvider, loggerConfiguration) =>
            loggerConfiguration.WriteTo.XUnit3TestOutput(
                serviceProvider.GetRequiredService<XUnit3TestOutputSink>()));

        return base.CreateHost(builder);
    }

    public void SetTestOutputHelper(ITestOutputHelper testOutputHelper) =>
        Services.GetRequiredService<XUnit3TestOutputSink>().TestOutputHelper = testOutputHelper;
}

[Collection(nameof(SampleCollection))]
public class SampleSuccessTests(SampleFixture fixture, ITestOutputHelper testOutputHelper)
{
    private readonly SampleFixture _fixture = fixture.SetTestOutputHelper(testOutputHelper);

    [Fact]
    public async Task Get_ById_Success()
    {
        var client = _fixture.Factory.CreateClient();
        var response = await client.GetFromJsonAsync<Todo>("/todos/1", CancellationToken.None);
        Assert.NotNull(response);
    }
    
    [Fact]
    public async Task Get_List_Success()
    {
        var client = _fixture.Factory.CreateClient();
        var response = await client.GetFromJsonAsync<Todo[]>("/todos", CancellationToken.None);
        Assert.NotNull(response);
    }
}
Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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 Serilog.Sinks.XUnit3:

Package Downloads
ConsumerDataRight.ParticipantTooling.MockSolution.TestAutomation

Shared test automation code for Consumer Data Right mock solutions.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Serilog.Sinks.XUnit3:

Repository Stars
Stepami/hydrascript
TypeScript & Go inspired small interpreted programming language written in C#. The interpreter built with DDD principles and Clean Architecture. Implementation powered by Source Generators
Version Downloads Last Updated
2.1.2 40,884 10/19/2026
2.1.1 22,406 9/28/2026
2.1.0 59,914 8/20/2026
2.0.0 14,322 8/12/2026
1.3.0 40,648 8/12/2026
1.2.4 437 8/12/2026
1.2.3 286 8/12/2026
1.2.2 327 8/12/2026
1.2.0 490,792 11/13/2025
1.1.0 16,331 9/24/2025
1.0.0 4,476 9/22/2025