LogAssertions 0.7.0
Prefix ReservedSee the version list below for details.
dotnet add package LogAssertions --version 0.7.0
NuGet\Install-Package LogAssertions -Version 0.7.0
<PackageReference Include="LogAssertions" Version="0.7.0" />
<PackageVersion Include="LogAssertions" Version="0.7.0" />
<PackageReference Include="LogAssertions" />
paket add LogAssertions --version 0.7.0
#r "nuget: LogAssertions, 0.7.0"
#:package LogAssertions@0.7.0
#addin nuget:?package=LogAssertions&version=0.7.0
#tool nuget:?package=LogAssertions&version=0.7.0
LogAssertions
Scope: Test projects only. Not intended for production code.
Framework-agnostic core for fluent log assertions over Microsoft.Extensions.Logging.Testing.FakeLogCollector.
Most users want
LogAssertions.TUnit, not this package directly. This is the shared engine; framework-specific adapter packages add the assertion entry points your test framework expects.
What's in this package
ILogRecordFilter: composable filter interface (Matches(FakeLogRecord)+Description).LogFilter: static factory for every built-in filter shape (AtLevel,Containing,WithMessageTemplate,WithException,WithoutException(v0.6.0+),WithInnerException(v0.4.0+),WithInnerExceptionMessage(v0.4.0+),WithProperty,WithProperty<T>(v0.6.0+),WithCategory,WithEventId,WithScope,WithScopeProperty,WithScopeProperty<T>(v0.6.0+),WithScopeProperties(v0.4.0+),Where, etc.) plus combinators (All,Any,Not).LogAssertionRendering: failure-snapshot rendering (4-character level abbreviation, props line, scopes line, exception line) withDumpVerbosity-controlled detail level (v0.4.0+:Compact/Default/Verbose). Used by adapter packages and by theDumpToextension below.LogCollectorBuilder.Create(LogLevel): one-line factory returning a wired(ILoggerFactory, FakeLogCollector)tuple.- Inspection extensions on
FakeLogCollector:Filter(params ILogRecordFilter[])returns matching records,CountMatching(params ILogRecordFilter[])returns the count,DumpTo(TextWriter)andDumpTo(TextWriter, DumpVerbosity)(v0.4.0+) write the captured-records snapshot.
Test-framework adapters
| Package | Test framework | Status |
|---|---|---|
LogAssertions.TUnit |
TUnit | Available now |
LogAssertions.NUnit |
NUnit | Possible if there is demand |
LogAssertions.xUnit |
xUnit | Possible if there is demand |
LogAssertions.MSTest |
MSTest | Possible if there is demand |
If you'd find a non-TUnit adapter useful, open a feature request: adapters are not built proactively.
Installation
dotnet add package LogAssertions.TUnit
LogAssertions comes transitively. You don't need to install it directly unless you're building your own adapter package.
Direct use
If you're building a custom adapter or want non-asserting access to filtered records, the public surface lets you compose filters and inspect the collector without going through any test-framework's assertion type:
using LogAssertions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
var (factory, collector) = LogCollectorBuilder.Create();
using (factory)
{
var logger = factory.CreateLogger("MyCategory");
logger.LogWarning("validation failed: TimeoutMs out of range");
// Compose a reusable filter:
ILogRecordFilter validationWarning = LogFilter.All(
LogFilter.AtLevel(LogLevel.Warning),
LogFilter.Containing("validation", StringComparison.Ordinal));
// Inspect without asserting:
int count = collector.CountMatching(validationWarning); // 1
var matches = collector.Filter(validationWarning); // IReadOnlyList<FakeLogRecord>
using var writer = new StringWriter();
collector.DumpTo(writer); // print the captured-records snapshot
}
Building a custom adapter
A test-framework adapter package needs to:
- Reference
LogAssertions. - Provide entry-point methods that surface a fluent chain over the framework's assertion type.
- Use
LogFilterfactory methods to build the filter chain. - Use
LogAssertionRendering.AppendCapturedRecords(...)for failure-message snapshot output (so the format stays consistent across adapters).
LogAssertions.TUnit is the reference implementation: see its source for the pattern.
Stability
- The public surfaces above (
ILogRecordFilter,LogFilter,LogAssertionRendering,LogCollectorBuilder, the extension methods onFakeLogCollector) are semver-bound. Breaking changes require a major version bump. - The exact text format of failure-message snapshots rendered by
LogAssertionRenderingis not stable. May gain extra detail or change formatting in any release. Pin filter match counts and broad markers in tests, not exact failure text.
License
MIT. Copyright (c) 2026 John Verheij.
| Product | Versions 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. |
-
net10.0
- Microsoft.Extensions.Diagnostics.Testing (>= 10.7.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on LogAssertions:
| Package | Downloads |
|---|---|
|
LogAssertions.TUnit
TUnit-native fluent log-assertion DSL using [AssertionExtension] over Microsoft.Extensions.Logging.Testing.FakeLogCollector. Provides Assert.That(collector).HasLogged()/HasNotLogged() with filter and terminator chaining; emits captured-records snapshot in failure messages. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.13.1 | 131 | 11/2/2026 |
| 0.13.0 | 148 | 11/1/2026 |
| 0.12.0 | 637 | 7/11/2026 |
| 0.11.0 | 1,545 | 7/11/2026 |
| 0.10.1 | 305 | 6/26/2026 |
| 0.10.0 | 300 | 6/25/2026 |
| 0.9.0 | 199 | 6/15/2026 |
| 0.8.0 | 246 | 6/14/2026 |
| 0.7.0 | 215 | 6/11/2026 |
| 0.6.3 | 176 | 6/6/2026 |
| 0.6.2 | 165 | 6/5/2026 |
| 0.6.1 | 252 | 6/4/2026 |
| 0.6.0 | 163 | 6/2/2026 |
| 0.5.0 | 274 | 5/14/2026 |
| 0.4.1 | 360 | 5/12/2026 |
| 0.4.0 | 190 | 5/7/2026 |
| 0.3.0 | 220 | 5/2/2026 |
| 0.2.4 | 174 | 5/2/2026 |
| 0.2.3 | 148 | 5/1/2026 |
| 0.2.2 | 147 | 5/1/2026 |
View the rendered release notes: https://github.com/JohnVerheij/LogAssertions.TUnit/releases/tag/v0.7.0
Minor release. Adds a key-only `WithScopeProperty(string key)` overload for asserting a scope property is present without asserting its value. Purely additive.
### Added
- **`WithScopeProperty(string key)`** on `LogFilter` and on the `HasLogged()` / `HasNotLogged()` chain asserts that a record carried a scope property at `key`, regardless of its value (a `null` value still counts as present). The existing two-argument overloads assert a value; this one asserts only presence. It covers the common case of a scope whose value is set at the production log site and is not visible to the test, such as a caller-info scope (`CallerFile` / `CallerLine` / `CallerMember` from `[CallerFilePath]` / `[CallerLineNumber]` / `[CallerMemberName]`). Pairs with `HasNotLogged().WithScopeProperty(key)` to assert a scope key was never attached.
### Changed
- README adds a **"Prefer structured matchers over substring matching"** guide under the migration section: a table mapping common `.Containing("...")` shapes to the structured matcher that is more robust (`.WithProperty`, `.WithException<T>`, `.WithScopeProperty`, `.WithMessageTemplate`, `HasLoggedSequence`), with the rationale that substring matching couples a test to rendered message text that rots when a template is reworded.
- Bumped `PackageValidationBaselineVersion` from `0.6.1` to `0.6.3` on both packages so ApiCompat strict-mode validates `0.7.0` against the most recently published baseline. The new overload is recorded as an additive difference in `CompatibilitySuppressions.xml`.