-
Notifications
You must be signed in to change notification settings - Fork 246
Should frameworks like Serilog, NLog implement their own ILoggerFactory? #420
Comments
I think this is a nice idea, but I'm curious if there is enough time to change this. (from Microsoft's viewpoint) |
Interesting angle, thanks for looping me in. I can see how this could work, especially if the the whole (I am, I have to admit, incredibly stoked that we have RC2 and RTM expected soon for the run-time portions of .NET Core and ASP.NET Core, and wouldn't hold that up for love or money :-)) |
I personally also think that these concerns should have been split because But still, implementing an ILoggerFactory in Serilog, NLog, ... would be a great first step to allow people, who don't need other MS specific providers to completely circumvent that concept. Of course, you would still have to implement an ILoggerProvider because most people will use that (because that's what's in the samples), but I guess the effort for implementing the ILoggerFactory wouldn't be too big. |
@cwe1ss I whole-heartly agree with this. To me, the It might definitely be too late, but just in case, I really think we should create an issue addressing this. I mean, writing a logging abstraction framework should maybe take a week or two, where as the aspnet/logging project dates back to the beginning of 2014. All this time, over 400 commits for such an awkward situation? |
@davidfowl is there even a theoretical chance that any of the following might be considered at some point in the future?
If you see value in discussing/tracking any of these breaking changes, I would be happy to create separate issues with more details for them. After your answer, I'll also close this issue, since implementing ILoggerFactory's is up to the 3rd party loggers and should probably be tracked in their repositories. |
Anymore news/info about this issue? cc @davidfowl |
Did any of the frameworks ever look at doing this to see what it would look like? I agree the interfaces are a bit messy as providers are really a specific implementation detail of our public interface ILoggerFactory
{
ILogger CreateLogger(string categoryName);
} Get rid of the extension methods on var host = new WebHostBuilder()
.UseLoggerFactory(loggerFactory =>
{
// Here we get a concrete `LoggerFactory`
loggerFactory.AddConsole();
})
.UseKestrel()
.UseStartup<Startup>()
.Build(); /cc @Eilon @muratg @DamianEdwards @glennc I think we should do some thinking here for 2.0 |
I created some abstraction for current project I'm working on public interface ILoggerFactoryAdapter
{
void AddLog(ILoggerFactory loggerFactory);
void AddCorrelationProperty<T>(string propertyName, T value);
//TODO:Refactoring tip, put in some other Interface
void RefreshConfiguration();
} so in Startup.cs Configure method I have something like public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, ILoggerFactoryAdapter loggerFactoryAdapter)
{
...
loggerFactoryAdapter.AddLog(loggerFactory);
...
} Basically, my Idea is that I can switch |
@davidfowl we haven't done any experimentation with this for Serilog; agreed it sounds like an interesting opportunity to dig into. If anyone's interested in PR'ing up (even some sketchy) changes for the Serilog provider, the repo is at: https://github.com/serilog/serilog-extensions-logging. I'd love to take a look but won't have any time in the next week or two. |
I like this enough to move it into 2.0 and discuss it more with that timeframe in mind. |
@BrennanConroy assigning this to you |
I believe we have done the work on our side for this. |
@BrennanConroy yes, thank you very much!!! |
fyi: there might be a design issue with the changes introduced here and how aspnet/Hosting handles logging: aspnet/Hosting#1071 |
cc @304NotModified @nblumhardt
Since it is now possible to pass a custom
ILoggerFactory
into theWebHostBuilder
by callingIWebHostBuilder.UseLoggerFactory(ILoggerFactory loggerFactory)
, I'm wondering if it would make more sense for 3rd party frameworks like Serilog, NLog to implement their ownILoggerFactory
in addition to (or even instead of) aILoggerProvider
?To me, it seems like
ILoggerProvider
is better for actual outputs like Console, EventLog, ... andILoggerFactory
would be better for frameworks. It's not really useful to combine a provider fromM.E.L
(e.g. Console) with sinks from Serilog because Serilog has a sink for each M.E.L-provider anyway. So, routing all logs throughMicrosoft.Extensions.Logging.dll
seems like an unnecessary step.If all logging frameworks would implement
ILoggerFactory
, we could also think about removing the assemblyMicrosoft.Extensions.Logging.dll
fromaspnet/hosting
! The choice of a logging framework is the same as the choice of a server (e.g. Kestrel) IMO. This means,Microsoft.Extensions.Logging
(which is just Microsoft's implementation) could be part of the template, but if someone wants to use Serilog/NLog he would remove the dependency and therefore wouldn't have Microsoft.Extensions.Logging.dll on disk anymore.The text was updated successfully, but these errors were encountered: