-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Set up a way to render logs when a test fails.
e.g.
public void Test()
{
var logProvider = new TestCaptureLoggerProvider();
using var rox = logProvider.RenderOnTestFailure(
p => p.GetLogEntriesFor<ServiceBeingTested>(),
Formatter.SimpleBySequence,
Sink.Console);
// do test stuff.
rox.Success(); // If it gets here then logs are not rendered.
// If the test method ends by throwing an exception the logs are automatically rendered.
// i.e. rox is disposable, and if the success flag is not set, then anything that matches
// the filter is rendered.
}
RenderOnTestFailure
has three arguments
- A function that filters the captured logs. e.g.
p => GetLogsWithExceptions()
- A formatter for rendering the log. e.g.
l => $"[{le.LogLevel}] {le.FormattedMessage}"
- A sink for forwarding the rendered log. e.g.
s => XunitOutputHelper.WriteLine(s)
This method is available on the log provider and the logger itself.
Metadata
Metadata
Assignees
Labels
No labels