Last active
December 17, 2020 14:51
-
-
Save iamNoah1/51df957e5f94186e75e6c783afe4922d to your computer and use it in GitHub Desktop.
.NetCore Console Logging in Unit Tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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