Reputation: 8669
I did this:
public static IWebHost BuildWebHost(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseUrls("http://0.0.0.0:5000")
.ConfigureLogging(ConfigureLogging)
.Build();
}
private static void ConfigureLogging(WebHostBuilderContext hostingContext, ILoggingBuilder logging)
{
logging.ClearProviders();
}
And my appsettings.json
:
{
}
But still.. I get exceptions logged to Console
- can somebody explain why? Pointers?
Upvotes: 4
Views: 3524
Reputation: 1284
You can configure the logging while creating the webhost like this
private static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureLogging(config => {
config.ClearProviders();
})
.UseKestrel()
.UseStartup<Startup>();
The config.ClearProviders() will remove all logging service and only produce minimal information
Upvotes: 3
Reputation: 31832
The framework has a default ILoggerFactory
that it will use if none is registered.
When you add UseSerilog()
, this will replace the default factory, and the default console logging will go away.
Upvotes: 0