Serilog ReadFrom Configuration
I configured like this
public static void Main(string[] args)
{
var _config = new ConfigurationBuilder()
.AddJsonFile("loggerconfig.json") //mantained separate config file
.Build();
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(_config)
.CreateLogger();
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseSerilog()
.UseStartup<Startup>();
and this is the better way according to Serilog.
I configure it like that:
return WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration
.ReadFrom.Configuration(hostingContext.Configuration))
.Build();
by default Serilog
look for Serilog
section in configuration