Serilog.Sinks.XUnit3
1.0.0
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
<PackageReference Include="Serilog.Sinks.XUnit3" Version="1.0.0" />
<PackageVersion Include="Serilog.Sinks.XUnit3" Version="1.0.0" />
<PackageReference Include="Serilog.Sinks.XUnit3" />
paket add Serilog.Sinks.XUnit3 --version 1.0.0
#r "nuget: Serilog.Sinks.XUnit3, 1.0.0"
#:package Serilog.Sinks.XUnit3@1.0.0
#addin nuget:?package=Serilog.Sinks.XUnit3&version=1.0.0
#tool nuget:?package=Serilog.Sinks.XUnit3&version=1.0.0
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 | Versions 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. |
-
net8.0
- Serilog (>= 4.3.0)
- xunit.v3.extensibility.core (>= 3.0.1)
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
|