I'm using vs 2017, writing a netcoreapp2.0 library, and testing it with a UnitTest project (XUnit and NUnit give same results).
I've noticed that unless I'm forcefully Disposing of my Serilog logger, only the first line will end up in Seq.
Here are my 2 classes. The library one:
public class Class1
{
public static Logger _log;
public Class1(Logger log)
{
_log = log;
_log.Verbose("Class 1 constructor finished");
}
public void LogMessage(string s)
{
_log.Debug("Got message: {Message}", s);
}
}
And the Unit test:
public class UnitTest1
{
public static Logger _log = new LoggerConfiguration()
.WriteTo.Seq("http://localhost:5341", Serilog.Events.LogEventLevel.Verbose)
.MinimumLevel.Verbose()
.CreateLogger();
[Fact]
public void Test1()
{
_log.Debug("Test 1 logging");
var c = new Class1(_log);
c.LogMessage("Logging from test");
_log.Information("Test finished");
_log.Dispose(); // Without this, only "Test 1 logging" is logged.
}
}
Referenced assemblies (from unit test project):
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" />
<PackageReference Include="serilog" Version="2.5.0" />
<PackageReference Include="serilog.sinks.seq" Version="3.3.3" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
Any suggestions?
(Here's a link to a demo project, open with vs 2017 restore the packages and run the test : demo project )
Dispose()
- it's the same thing essentially asCloseAndFlush()
. HTH! – Picardi