Skip to content

Instantly share code, notes, and snippets.

@iamNoah1
Last active December 17, 2020 14:51
Show Gist options
  • Save iamNoah1/51df957e5f94186e75e6c783afe4922d to your computer and use it in GitHub Desktop.
Save iamNoah1/51df957e5f94186e75e6c783afe4922d to your computer and use it in GitHub Desktop.
.NetCore Console Logging in Unit Tests
...
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Logging;
public class Tester
{
[Fact]
public void TestSomeClassThatUsesLogging()
{
using var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddConsole();
builder.AddFilter(level => level >= LogLevel.Debug);
});
var logger = loggerFactory.CreateLogger<ClassThatUsesLogging>();
ClassThatUsesLogging classUnderTest = new ClassThatUsesLogging(logger);
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment