Streamlines integration testing by forwarding application logs directly into the xUnit test output, perfect for debugging in CI/CD pipelines.
$ dotnet add package CSharpEssentials.LoggerHelper.xUnit
A lightweight xUnit sink for CSharpEssentials.LoggerHelper, designed to make integration tests and CI/CD pipelines more observable by streaming logs directly into the xUnit output window.
IdTransaction, Action, ApplicationName, …).dotnet add package CSharpEssentials.LoggerHelper.Sink.xUnit
Add the sink to your appsettings.LoggerHelper.json:
{
"Serilog": {
"SerilogConfiguration": {
"SerilogCondition": [
{
"Sink": "xUnit",
"Level": [ "Information", "Warning", "Error", "Fatal" ]
}
]
}
}
}
In your test class, link the sink to xUnit’s output stream:
public class MinimalEndpointTests : IClassFixture<WebApplicationFactory<Program>>
{
private readonly WebApplicationFactory<Program> _factory;
public MinimalEndpointTests(WebApplicationFactory<Program> factory, ITestOutputHelper output)
{
_factory = factory;
// 🚨 REQUIRED: link logger to xUnit output
XUnitTestOutputHelperStore.SetOutput(output);
}
[Fact]
public async Task Login_ShouldTimeout_WhenTokenInvalid()
{
var client = _factory.CreateClient();
var response = await client.GetAsync("/auth/check");
response.EnsureSuccessStatusCode();
}
}