'What is the preferred way to configure logging with Serilog in NetCore when using a generic Host?
How should Serilog be configured if you want to use it within NetCore and a generic Host (or IHost), not a WebHost or something else?
There are the two options I found:
- Use
.UseSerilog()from theSerilog.Extensions.HostingNuGet package:
var host = Host.CreateDefaultBuilder()
.UseSerilog()
.UseSystemd()
.UseWindowsService()
.Build();
- Use
.ConfigureLogging()and.AddSerilog()from theSerilogNuGet package:
.ConfigureLogging(
logging =>
{
logging.AddSerilog();
});
So there are two questions now:
- Do both options result in the same behaviour and if not, what's the difference?
- Which method should be used preferred (Or are they equal and you can use as you like)?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
