Skip to main content

aweXpect.Logging

aweXpect.Logging contains expectations for the log records that are written with Microsoft.Extensions.Logging. It is an extension for aweXpect.

Installation​

dotnet add package aweXpect.Logging

It does not include aweXpect itself.

At a glance​

// collect the log records with a FakeLogger from Microsoft.Extensions.Diagnostics.Testing
FakeLogCollector collector = new();
ILogger logger = new FakeLogger(collector);
logger.LogWarning("Retry limit reached");

// verify that a record with the log level was logged
await That(collector).LoggedWarning();

A failing expectation lists the collected records. If only an error was logged, LoggedWarning() would fail with:

Failure message
Expected that collector
logged a record with level Warning at least once,
but it did not log any such record

Records:
[
[Error] "Retry limit reached"
]

Overview​

ExpectationSubjectSummary
LoggedFakeLogCollector, FakeLoggerlogged at least one record with the log level, e.g. LoggedWarning()
DidNotLogFakeLogCollector, FakeLoggerlogged no record with the log level, e.g. DidNotLogError()
ThenFakeLogCollector, FakeLoggerlogged further records after a matching record, in the given order
WithinFakeLogCollector, FakeLoggerreads the records repeatedly until the timeout, e.g. for a background service