Expectations for logging with Microsoft.Extensions.Logging for aweXpect.
// 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:
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"
]
| Expectation | Subject | Summary |
|---|---|---|
Logged |
FakeLogCollector, FakeLogger |
logged at least one record with the log level, e.g. LoggedWarning() |
DidNotLog |
FakeLogCollector, FakeLogger |
logged no record with the log level, e.g. DidNotLogError() |
The full documentation is available at docs.testably.org:
- Log records:
LoggedandDidNotLogon the records of aFakeLogCollector