Diagnostics for examining logs in automated tests.
Available from v2.1 in package Stravaig.Extensions.Logging.Diagnostics.XUnit
Writes the logs to XUnit’s test output helper.
IEnumerable<LogEntry> logEntries
: a sequence of log entries to renderFunc<LogEntry, string>? formatter
: (optional) A function that formats the LogEntry to a string. If omitted then the Formatter.SimpleBySequence
formatter is used.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class ThingamajigTests
{
private ITestOutputHelper _output;
public ThingamajigTests(ITestOutputHelper output)
{
_output = output;
}
[Fact]
public void TestTheThing()
{
// Arrange: Set up logger or provider, e.g.
var logProvider = new TestCaptureLoggerProvider();
// Act: Perform the action that creates the log entries
// Assert: Test the results
_output.WriteLogs(logProvider.GetAllLogEntries())
}
}
ITestOutputHelper.WriteLogs(ITestCaptureLogger logger, Func<LogEntry, string>? formatter = null)
ITestCaptureLogger
and outputs all of the log messages captured by that logger.ITestOutputHelper.WriteLogs(TestCaptureLoggerProvider provider, Func<LogEntry, string>? formatter = null)
TestCaptureLoggerProvider
and outputs all of the log messages captured by all the loggers in the provider.