I noticed that .NET Core Unit Tests capture the output send through tracing (via Trace.Write()) and through the console (via Console.Write()).
It took me some time before I had the correct code to get the Microsoft.Extensions.Logging data written to my test logs.
So here is a small code snippet in case you don’t want to search for it yourself:
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
var serviceCollection = new ServiceCollection(); | |
var config = new ConfigurationBuilder() | |
.AddJsonFile("appsettings.json") | |
.Build(); | |
serviceCollection | |
.AddLogging(loggingBuilder => loggingBuilder.AddConsole()); | |
Remark: Don’t forget to include the Microsoft.Extensions.Logging.Console nuget package.