You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.
Initializing the logging system should be one of the first things in an app. Now the LoggerFactory is created in the constructor of WebHostBuilder and it can be configured by calling webHostBuilder.ConfigureLogging or by configuring the logger in your Startup class.
However, there are scenarios where you want to initialize your logging system before creating a WebHostBuilder:
your application hosts multiple WebHosts
some stuff happens before you create the WebHost (e.g. registering with and getting the hosting url from Service Fabric)
your app might be a GUI app that just happens to host a WebAPI for whatever reason, ...
For this reason, I suggest that it should be possible to optionally pass an existing LoggerFactory into the WebHostBuilder. This could be done by introducing a second constructor WebHostBuilder(ILoggerFactory loggerFactory) or by introducing another method .UseLoggerFactory(ILoggerFactory loggerFactory).
I would prefer the second constructor because this makes sure that there's always just one instance of the factory and you can't mix up the calls to UseLoggerFactory and ConfigureLogging.
If you agree to this, I'd be happy to create a pull request!
The text was updated successfully, but these errors were encountered:
cwe1ss
changed the title
Pass LoggerFactory to WebHostBuilder
Pass existing LoggerFactory to WebHostBuilder
Mar 17, 2016
Closed to continue discussion directly in the pull request. I hope that's ok - I haven't figured out yet, whether it's better to have discussions in an issue or PR.
@cwe1ss Don't close the issue until you have merged the PR. We use issues to track progress. Discussions can happen in both places though it's more design oriented in issues and more implementation oriented in PRs
Initializing the logging system should be one of the first things in an app. Now the
LoggerFactory
is created in the constructor ofWebHostBuilder
and it can be configured by callingwebHostBuilder.ConfigureLogging
or by configuring the logger in yourStartup
class.However, there are scenarios where you want to initialize your logging system before creating a
WebHostBuilder
:For this reason, I suggest that it should be possible to optionally pass an existing
LoggerFactory
into theWebHostBuilder
. This could be done by introducing a second constructorWebHostBuilder(ILoggerFactory loggerFactory)
or by introducing another method.UseLoggerFactory(ILoggerFactory loggerFactory)
.I would prefer the second constructor because this makes sure that there's always just one instance of the factory and you can't mix up the calls to
UseLoggerFactory
andConfigureLogging
.If you agree to this, I'd be happy to create a pull request!
The text was updated successfully, but these errors were encountered: