Skip to main content

aweXpect.Logging

Nuget

aweXpect.Logging contains expectations for the log records that are written with Microsoft.Extensions.Logging.

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 Expect.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()

Documentation​

The full documentation is available at docs.testably.org:

  • Log records: Logged and DidNotLog on the records of a FakeLogCollector