This repository was archived by the owner on Dec 13, 2018. It is now read-only.
This repository was archived by the owner on Dec 13, 2018. It is now read-only.
Consider a way to configure logging provider using the DI system #346
Closed
Description
This code always looks a little bizzare:
public void ConfigureServices(IServiceCollection services)
{
...
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole();
...
}
The fact that hosting adds the default ILoggerFactory is fine, but having to resolve it in Configure to add logging providers seems anti to how we've integrated the rest of the stack (it feels bolted on). Also, configuring logging in ConfigureServices would mean the only thing we configure in Configure would be the http stuff (for the most part).
Proposal 1
The default logger factory should resolve an IEnumerable in its ctor.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddConsoleLogger(LogLevel.Debug);
}
public LoggerFactory(IEnumerable<ILoggerProvider> loggerProviders)
The only downside if that more extension methods get added to IServiceCollection
but meh.
Proposal 2
Add LoggerOptions
and hang an IList off it.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.Configure<LoggerOptions>(options =>
{
options.Providers.AddConsole(LogLevel.Debug);
});
}