Integration between .NET logging and xUnit output. In short, it adds logs to the output window of your test runner.
public ManualCreation_Example(ITestOutputHelper output)
{
_fooService = new FooService(output.For<FooService>());
//or (the same)
_fooService = new FooService(new XunitLogger<FooService>(output));
}
public DependencyInjection_Example(ITestOutputHelper output)
{
var services = new ServiceCollection();
services.AddLogging(cfg =>
{
cfg.AddXunit(output);
});
services.AddTransient<FooService>();
var provider = services.BuildServiceProvider();
_fooService = provider.GetRequiredService<FooService>();
}
var logger = new XunitLogger(output, "fooCategory", cfg =>
{
cfg.MinimumLogLevel = LogLevel.Warning;
cfg.CategoryName = CategoryNameStyle.Short;
});
var mock = new Mock<ITestOutputHelper>();
var logger = mock.Object.For<FooService>();
logger.Log(LogLevel.Warning, "fooMessage");
mock.Verify(m => m.WriteLine(It.IsAny<string>()), Times.Once());