LogAssertions.TUnit 0.4.0

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

LogAssertions.TUnit

NuGet Downloads License: MIT .NET

Scope: Test projects only. Not intended for production code.

TUnit-native fluent log-assertion DSL on top of Microsoft.Extensions.Logging.Testing.FakeLogCollector. AOT-compatible, trimmable, no reflection.

Full documentation, full filter reference, design notes, and roadmap: github.com/JohnVerheij/LogAssertions.TUnit

Install

dotnet add package LogAssertions.TUnit

LogAssertions (the framework-agnostic core) comes transitively. Requirements: TUnit 1.43.11+, .NET 10.

Quick start

using LogAssertions;
using Microsoft.Extensions.Logging;

[Test]
public async Task Validation_failure_is_logged()
{
    var (factory, collector) = LogCollectorBuilder.Create();
    using (factory)
    {
        var logger = factory.CreateLogger<MyValidator>();
        new MyValidator(logger).Validate(invalidInput);

        await Assert.That(collector)
            .HasLogged()
            .AtLevel(LogLevel.Warning)
            .Containing("validation failed", StringComparison.Ordinal)
            .Once();

        await Assert.That(collector).HasNotLogged().AtLevelOrAbove(LogLevel.Error);
    }
}

Entry points

Method Default expectation
HasLogged() At least 1 matching record
HasNotLogged() Zero matching records
HasLoggedSequence() Records appear in order; Then() separates steps

Plus shorthands: HasLoggedOnce(), HasLoggedExactly(int), HasLoggedAtLeast(int), HasLoggedBetween(int, int), HasLoggedNothing(), HasLoggedWarningOrAbove(), HasLoggedErrorOrAbove().

Filters chain with AND semantics: AtLevel, AtLevelOrAbove, Containing, WithException<T>, WithInnerException<T> (v0.4.0+), WithInnerExceptionMessage (v0.4.0+), WithProperty, WithCategory, WithEventId, WithScope<T>, WithScopeProperty, WithScopeProperties (v0.4.0+), plus combinators MatchingAny/MatchingAll/Not/WithFilter for composable filter objects. Sequence assertions chain via Then() (strict order) or ThenAnyOrder(...) (v0.4.0+) (concurrent group; sub-steps may match in any order). Full filter reference on GitHub.

Cookbook

Assert no errors were logged:

await Assert.That(collector).HasNotLogged().AtLevelOrAbove(LogLevel.Error);

Assert a specific call site was hit (anchored on the message template, not the substituted value):

await Assert.That(collector).HasLogged()
    .WithMessageTemplate("Order {OrderId} processed").AtLeast(1);

Assert a specific exception flowed through a logger:

await Assert.That(collector).HasLogged()
    .AtLevel(LogLevel.Error)
    .WithException<DbUpdateConcurrencyException>()
    .Once();

Assert a wrapped exception (gRPC / RPC pattern, v0.4.0+):

await Assert.That(collector).HasLogged()
    .WithException<RpcException>()
    .WithInnerException<TimeoutException>()
    .Once();

Assert a startup → work → shutdown sequence:

await Assert.That(collector).HasLoggedSequence()
    .WithEventName("Startup")
    .Then().AtLevel(LogLevel.Information).Containing("processed", StringComparison.Ordinal)
    .Then().WithEventName("Shutdown");

Assert a fan-out completion in any order (v0.4.0+):

await Assert.That(collector).HasLoggedSequence()
    .Containing("Request received", StringComparison.Ordinal)
    .ThenAnyOrder(
        s => s.Containing("Auth check passed", StringComparison.Ordinal),
        s => s.Containing("Quota check passed", StringComparison.Ordinal))
    .Then().Containing("Response sent", StringComparison.Ordinal);

Assert several invariants and report all failures together:

await Assert.That(collector).AssertAllAsync(
    c => c.HasLogged().AtLevel(LogLevel.Information).AtLeast(1),
    c => c.HasNotLogged().AtLevelOrAbove(LogLevel.Error),
    c => c.HasLoggedSequence().WithEventName("Startup").Then().WithEventName("Shutdown"));

Failure diagnostics

On a failed assertion, the exception message includes the expected match count, the actual count, and a snapshot of every captured record (level abbreviation, category, message, structured properties, scopes, exception). No need for Console.WriteLine debugging — every dimension you can filter on is also rendered in the failure message.

Full failure-diagnostics example, design notes, stability intent, and roadmap on GitHub.

License

MIT — Copyright (c) 2026 John Verheij

Product Compatible and additional computed target framework versions.
.NET 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. 
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.4.0 41 5/7/2026
0.3.0 156 5/2/2026
0.2.4 124 5/2/2026
0.2.3 102 5/1/2026
0.2.2 92 5/1/2026
0.2.1 102 5/1/2026
0.2.0 96 5/1/2026
0.1.0 104 5/1/2026

See CHANGELOG.md