-
Notifications
You must be signed in to change notification settings - Fork 307
Pass existing LoggerFactory into WebHostBuilder #661
Conversation
Hi @cwe1ss, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution! The agreement was validated by .NET Foundation and real humans are currently evaluating your PR. TTYL, DNFBOT; |
Do you think that |
I think we should support this but not via the constructor |
Ok. How about this:
if (_loggerFactory != null)
{
services.AddSingleton(_loggerFactory);
}
services.AddLogging(); The existing method If you want to keep it, we would have to do the following:
var loggerFactory = _loggerFactory ?? new LoggerFactory();
if (_configureLoggingDelegate != null)
{
_configureLoggingDelegate(loggerFactory);
}
services.AddSingleton(_loggerFactory);
services.AddLogging(); If you disagree, what would you suggest? |
I changed the code. It now has a Should it be possible to call |
Don't worry about Build being called more than once. |
While you're at it. add ConfigureLogging back to |
I added |
This needs a rebase |
… may be called multiple times
…quires reference to Microsoft.Extensions.Logging.Abstractions
hmm... I haven't done much merging/rebasing yet so I probably screwed it up. After trying a few things I ended up with duplicate commits. For that reason I did a complete rebase with Is it ok like this or should I do something else? |
thank you very much! |
As described in #658
I'm motivated so I couldn't wait for your answer. :) Feel free to reject it if you think this is not correct or if you want something changed.
It allows to pass an existing ILoggerFactory into the WebHostBuilder constructor. I think this is better than a
UseLoggerFactory
method because the LoggerFactory is already created in the constructor right now.I also added two tests. One checks if the host can actually resolve an ILoggerFactory and the second checks if the LoggerFactory passed in gets resolved correctly.
I added the tests at the top of the file because they are related to the constructor - I hope that's ok?!
BTW: Supporting a way to pass a LoggerFactor into the WebHostBuilder is also discussed here:
aspnet/Logging#346 ( @davidfowl @lodejard )