Table of Contents

Class FakeLogCollectorInspectionExtensions

Namespace
LogAssertions
Assembly
LogAssertions.dll

Non-asserting inspection helpers on Microsoft.Extensions.Logging.Testing.FakeLogCollector. Use these when a test needs to read the captured records as data: for downstream calculations, debugging output, or cross-checking: rather than to assert. None of these methods throw on mismatch.

public static class FakeLogCollectorInspectionExtensions
Inheritance
FakeLogCollectorInspectionExtensions
Inherited Members

Methods

CountMatching(FakeLogCollector, params ILogRecordFilter[])

Counts the records that satisfy every supplied filter. Convenience over collector.Filter(...).Count that avoids materialising the intermediate list.

public static int CountMatching(this FakeLogCollector collector, params ILogRecordFilter[] filters)

Parameters

collector FakeLogCollector

The collector to query.

filters ILogRecordFilter[]

The filters; AND-combined. Empty filter list counts every record.

Returns

int

The number of matching records.

Exceptions

ArgumentNullException

A required argument is null.

DumpTo(FakeLogCollector, TextWriter)

Renders every captured record to writer using the same formatter the failure-message snapshot uses (4-character level abbreviation, props line, scopes line, exception line). Equivalent to DumpTo(FakeLogCollector, TextWriter, DumpVerbosity) with Default.

public static void DumpTo(this FakeLogCollector collector, TextWriter writer)

Parameters

collector FakeLogCollector

The collector to dump.

writer TextWriter

The text destination. Must be non-null.

Exceptions

ArgumentNullException

A required argument is null.

DumpTo(FakeLogCollector, TextWriter, DumpVerbosity)

Verbosity-controlled overload of DumpTo(FakeLogCollector, TextWriter).

public static void DumpTo(this FakeLogCollector collector, TextWriter writer, DumpVerbosity verbosity)

Parameters

collector FakeLogCollector

The collector to dump.

writer TextWriter

The text destination. Must be non-null.

verbosity DumpVerbosity

How much detail to render per record. See DumpVerbosity for the contract of each level.

Exceptions

ArgumentNullException

A required argument is null.

Filter(FakeLogCollector, params ILogRecordFilter[])

Returns the records that satisfy every supplied filter, in original order. Useful when the test needs the matched records for further inspection rather than just an assertion. The returned list is a defensive copy not bound to the live collector.

public static IReadOnlyList<FakeLogRecord> Filter(this FakeLogCollector collector, params ILogRecordFilter[] filters)

Parameters

collector FakeLogCollector

The collector to query.

filters ILogRecordFilter[]

The filters; AND-combined. Empty filter list returns every record.

Returns

IReadOnlyList<FakeLogRecord>

The matched records.

Exceptions

ArgumentNullException

A required argument is null.