MartinCostello.Logging.XUnit.v3 0.5.1

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.
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.
// Install MartinCostello.Logging.XUnit.v3 as a Cake Addin
#addin nuget:?package=MartinCostello.Logging.XUnit.v3&version=0.5.1

// Install MartinCostello.Logging.XUnit.v3 as a Cake Tool
#tool nuget:?package=MartinCostello.Logging.XUnit.v3&version=0.5.1                

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. 
.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

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
0.5.1 3 12/26/2024
0.5.0 744 12/20/2024