Skip to content

trbenning/serilog-sinks-xunit

Folders and files

NameName
Last commit message
Last commit date
Dec 10, 2024
Dec 10, 2024
Apr 10, 2020
Feb 28, 2017
Jan 10, 2022
Feb 28, 2017
Aug 13, 2019
Dec 10, 2024
Jan 10, 2022

Repository files navigation

Build Status NuGet Version

serilog-sinks-xunit

The xunit test output sink for Serilog

What is it?

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

Installation

Install-Package Serilog.Sinks.XUnit

Example usage

using System;
using Xunit;
using Xunit.Abstractions;

public class Samples
{
    ILogger _output;

    public Samples(ITestOutputHelper output)
    {
        // Pass the ITestOutputHelper object to the TestOutput sink
        _output = new LoggerConfiguration()
            .MinimumLevel.Verbose()
            .WriteTo.TestOutput(output, Events.LogEventLevel.Verbose)
            .CreateLogger()
            .ForContext<IntegrationTests>();
    }

    [Fact]
    public void ExampleUsage()
    {
        // Use ILogger as you normally would. These messages will show up in the test output
        _output.Information("Test output to Serilog!");

        Action sketchy = () => throw new Exception("I threw up.");
        var exception = Record.Exception(sketchy);

        _output.Error(exception, "Here is an error.");
        Assert.NotNull(exception);
    }
}