R8.XunitLogger 1.1.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package R8.XunitLogger --version 1.1.2                
NuGet\Install-Package R8.XunitLogger -Version 1.1.2                
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="R8.XunitLogger" Version="1.1.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add R8.XunitLogger --version 1.1.2                
#r "nuget: R8.XunitLogger, 1.1.2"                
#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.
// Install R8.XunitLogger as a Cake Addin
#addin nuget:?package=R8.XunitLogger&version=1.1.2

// Install R8.XunitLogger as a Cake Tool
#tool nuget:?package=R8.XunitLogger&version=1.1.2                

R8.XunitLogger

Seamlessly integrate Xunit's ITestOutputHelper with Microsoft.Extensions.Logging using netstandard2.1, net6.0, net7.0 and net8.0. Capture logs from any layer of your application and send them to your test output, making debugging and integration testing a breeze. With minimal configuration, you can monitor log messages, helping to ensure your application runs smoothly.

Nuget Nuget Commit

Installation

dotnet add package R8.XunitLogger

Options

Option Description Default Value
MinimumLevel The minimum level of log messages to be written to the test output LogLevel.Information
IncludeTimestamp Whether to include timestamp in log messages true
IncludeScopes Whether to include scopes in log messages false
ColorBehavior Whether to enable colored log levels LoggerColorBehavior.Default
Categories The categories (namespaces) of log messages to be written to the test output null
ServiceProvider The service provider to be get appsettings.json from IConfiguration null

Colored Log Levels

Microsoft Visual Studio does not support colored log levels. However, JetBrains Rider does support colored log levels. If you want to enable colored log levels, you can use LoggerColorBehavior enum. If the value is set to LoggerColorBehavior.Default, the log levels will be colored in JetBrains Rider and will not be colored in Microsoft Visual Studio.


Usage

For simple testing:

public class UnitTest
{
    public UnitTest(ITestOutputHelper outputHelper)
    {
        _loggerFactory = new LoggerFactory().AddXunit(outputHelper, options =>
        {
            // ... options
        });
    }
}

For testing with Microsoft.Extensions.DependencyInjection:

public class IntegrationTest : IXunitLogProvider
{
    public IntegrationTest(ITestOutputHelper outputHelper)
    {
        var serviceProvider = new ServiceCollection()
            .AddLogging()
            .AddXunitLogger(message => OnWriteLine?.Invoke(message), options => 
            {
                // ... options
            })
            .BuildServiceProvider();
        this.OnWriteLine += outputHelper.WriteLine;
    }

    public event Action<string> OnWriteLine;
}

See more examples here

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.3 2,425 2/5/2024
1.1.2 366 2/1/2024
1.1.1 356 1/1/2024
1.1.0 121 1/1/2024
1.0.0 562 10/28/2023