I am trying to write unit tests with output to log - Serilog. But when I am debugging them in Visual Studio (Test Explorer) I can't see the Serilog output in console.
Any ideas?
public abstract class AbstractTest
{
static AbstractTest()
{
var loggers = new LoggerConfiguration()
.MinimumLevel.Verbose()
.Enrich.FromLogContext();
loggers.WriteTo.Logger(logger => logger
.WriteTo.Console(restrictedToMinimumLevel: LogEventLevel.Verbose));
Log.Logger = loggers.CreateLogger();
Log.Logger.Information("Logger is initialized");
}
}
[TestClass]
public class DemoTest : AbstractTest
{
private static ILogger log = Log.ForContext(typeof(DemoTest));
[TestMethod]
public void DemoTst()
{
log.Debug("test");
}
}
Neither 'Logger is initialized' nor 'test' is displayed in console.
I am using 'Serilog.AspNetCore' and 'Serilog.Sinks.Console'
Ok I found a solution.
You have to include package Serilog.Sinks.Debug
(here) into your project and initialize it with WriteTo.Debug()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With