MicrosoftExtensions.Logging.Xunit 1.3.0

dotnet add package MicrosoftExtensions.Logging.Xunit --version 1.3.0
                    
NuGet\Install-Package MicrosoftExtensions.Logging.Xunit -Version 1.3.0
                    
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="MicrosoftExtensions.Logging.Xunit" Version="1.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MicrosoftExtensions.Logging.Xunit" Version="1.3.0" />
                    
Directory.Packages.props
<PackageReference Include="MicrosoftExtensions.Logging.Xunit" />
                    
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 MicrosoftExtensions.Logging.Xunit --version 1.3.0
                    
#r "nuget: MicrosoftExtensions.Logging.Xunit, 1.3.0"
                    
#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 MicrosoftExtensions.Logging.Xunit@1.3.0
                    
#: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=MicrosoftExtensions.Logging.Xunit&version=1.3.0
                    
Install as a Cake Addin
#tool nuget:?package=MicrosoftExtensions.Logging.Xunit&version=1.3.0
                    
Install as a Cake Tool

MicrosoftExtensions.Logging.Xunit

NuGet

An xUnit v2 (xunit.abstractions) integration library for Microsoft.Extensions.Logging that forwards log messages to Xunit.Abstractions.ITestOutputHelper.

Scope

  • Targets xUnit v2 (Xunit.Abstractions.ITestOutputHelper from xunit.abstractions 2.0.3), which is distinct from xUnit v3's Xunit.ITestOutputHelper.
  • Implements ILoggerProvider, ISupportExternalScope (XunitLoggerProvider), and ILogger (XunitLogger) with formatted log levels, category names, event IDs, optional scopes, filtering, and exception stack traces.
  • Supports ILoggingBuilder registration via AddXunit(...) extensions and configuration via XunitLoggerOptions (IncludeScopes, MinLevel, Filter).
  • Multi-targeting: netstandard2.0, netstandard2.1, net462, net10.0, and net11.0.

Installation

dotnet add package MicrosoftExtensions.Logging.Xunit
# Required when using LoggerFactory.Create or AddLogging in the examples below
dotnet add package Microsoft.Extensions.Logging

Quick Start

using System;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Xunit;
using Xunit;
using Xunit.Abstractions;

public class SampleTests
{
    private readonly ILoggerFactory _loggerFactory;

    public SampleTests(ITestOutputHelper testOutputHelper)
    {
        _loggerFactory = LoggerFactory.Create(builder =>
        {
            builder.AddXunit(testOutputHelper, options =>
            {
                options.IncludeScopes = true;
                options.MinLevel = LogLevel.Debug;
            });
        });
    }

    [Fact]
    public void LogsToXunitOutput()
    {
        ILogger logger = _loggerFactory.CreateLogger<SampleTests>();
        logger.LogInformation("Hello from xUnit v2!");
        logger.LogWarning("Processing {ItemCount} items", 42);
    }
}

With Dependency Injection

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Xunit;
using Xunit;
using Xunit.Abstractions;

public class ServiceTests
{
    private readonly ServiceProvider _serviceProvider;

    public ServiceTests(ITestOutputHelper testOutputHelper)
    {
        var services = new ServiceCollection();
        services.AddLogging(builder =>
        {
            builder.AddXunit(testOutputHelper);
        });
        services.AddTransient<MyService>();

        _serviceProvider = services.BuildServiceProvider();
    }

    [Fact]
    public void TestService()
    {
        var service = _serviceProvider.GetRequiredService<MyService>();
        service.DoWork();
    }

    public sealed class MyService(ILogger<MyService> logger)
    {
        public void DoWork() => logger.LogInformation("Working...");
    }
}

License

LGPL-3.0-or-later WITH LGPL-3.0-linking-exception. See LICENSE for details.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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 was computed.  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 is compatible.  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.  net11.0 is compatible. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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 (1)

Showing the top 1 NuGet packages that depend on MicrosoftExtensions.Logging.Xunit:

Package Downloads
ChannelAdam.TestFramework.Xunit

A .NET library for using xUnit (and Moq) on top of the ChannelAdam Test Framework.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on MicrosoftExtensions.Logging.Xunit:

Repository Stars
CommunityToolkit/Datasync
A collection of libraries that implement a client-server system used for synchronizing data from a cloud-based database.
Version Downloads Last Updated
1.3.0 0 11/29/2026
1.2.1 454,439 8/22/2025
1.1.1 403,355 7/16/2025
1.1.0-beta.1.g5120d81 22,559 8/17/2022
1.0.0 827,035 2/23/2018

## [1.3.0] - 2026-11-29

### Added

- Added `XunitLoggerOptions` (`IncludeScopes`, `MinLevel`, `Filter`) and new constructor overloads on `XunitLoggerProvider` and `XunitLogger` while preserving backward-compatible defaults.
- Implemented `ISupportExternalScope` on `XunitLoggerProvider` and wired `XunitLogger.BeginScope<TState>` with optional scope rendering (`IncludeScopes = true`).
- Added `XunitLoggerExtensions.AddXunit` extension methods for `ILoggingBuilder` dependency-injection registration.

### Changed

- Added a `notnull` constraint and a nullable return annotation to `XunitLogger.BeginScope<TState>` on `net11.0`. Nullable state arguments or dereferencing the return value can produce compiler warnings when consumers rebuild.
- Aligned target frameworks to `netstandard2.0`, `netstandard2.1`, `net462`, `net10.0`, and `net11.0`.
- Added embedded Portable PDBs, SourceLink metadata, bounded package release notes, and shared license payloads.
- Clarified xUnit v2 (`Xunit.Abstractions.ITestOutputHelper`) scope in `<PackageDescription>` and `README.md`, and fixed the NuGet package ID in installation instructions.

## [1.2.1]

### Changed

- Re-licensed NuGet package to `LGPL-3.0-or-later WITH LGPL-3.0-linking-exception`.

Full changelog: https://github.com/hcoona/three/blob/main/src/public/lib/MicrosoftExtensions.Logging.Xunit/CHANGELOG.md