MartinCostello.Logging.XUnit.v3 0.5.1

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

xunit Logging

Introduction

MartinCostello.Logging.XUnit and MartinCostello.Logging.XUnit.v3 provide extensions to hook into the ILogger infrastructure to output logs from your xunit tests to the test output.

Usage

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Xunit;
using Xunit.Abstractions; // For xunit v2 - not required for xunit v3

namespace MyApp.Calculator;

public class CalculatorTests(ITestOutputHelper outputHelper)
{
    [Fact]
    public void Calculator_Sums_Two_Integers()
    {
        // Arrange
        using var serviceProvider = new ServiceCollection()
            .AddLogging((builder) => builder.AddXUnit(outputHelper))
            .AddSingleton<Calculator>()
            .BuildServiceProvider();

        var calculator = services.GetRequiredService<Calculator>();

        // Act
        int actual = calculator.Sum(1, 2);

        // Assert
        Assert.AreEqual(3, actual);
    }
}

public sealed class Calculator(ILogger<Calculator> logger)
{
    public int Sum(int x, int y)
    {
        int sum = x + y;

        logger.LogInformation("The sum of {x} and {y} is {sum}.", x, y, sum);

        return sum;
    }
}

Feedback

Any feedback or issues can be added to the issues for this project in GitHub.

License

This project is licensed under the Apache 2.0 license.

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. 
.NET Framework net472 is compatible.  net48 was computed.  net481 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 MartinCostello.Logging.XUnit.v3:

Package Downloads
Xunit.DependencyInjection.Logging

Support Microsoft.Extensions.Logging to ITestOutputHelper. public void Configure(IServiceProvider provider) { XunitTestOutputLoggerProvider.Register(provider); }

GitHub repositories (5)

Showing the top 5 popular GitHub repositories that depend on MartinCostello.Logging.XUnit.v3:

Repository Stars
martincostello/dotnet-minimal-api-integration-testing
An example of integration testing ASP.NET Core Minimal hosting and APIs
pengweiqhca/Xunit.DependencyInjection
Use Microsoft.Extensions.DependencyInjection to resolve xUnit test cases.
justeattakeaway/httpclient-interception
A .NET library for intercepting server-side HTTP requests
martincostello/sqllocaldb
SQL LocalDB Wrapper is a .NET library providing interop with the Microsoft SQL Server LocalDB Instance API
mburumaxwell/dependabot-azure-devops
Tools for updating dependencies in Azure DevOps repositories using https://dependabot.com
Version Downloads Last Updated
0.6.0 30,416 5/21/2025
0.5.1 143,679 12/26/2024
0.5.0 2,901 12/20/2024