Skip to content

Commit

Permalink
Merge pull request #205 from 304NotModified/aspnetcore2-register-3
Browse files Browse the repository at this point in the history
Register NLogProvider instead of NLogFactory
  • Loading branch information
304NotModified authored Oct 13, 2017
2 parents 5049700 + 0be3ee4 commit d0aee5c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions NLog.Web.AspNetCore/AspNetExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,29 +112,30 @@ public static IWebHostBuilder UseNLog(this IWebHostBuilder builder, NLogAspNetCo

builder.ConfigureServices(services =>
{
services.AddSingleton<ILoggerFactory>(serviceProvider =>
//note: when registering ILoggerFactory, all non NLog stuff and stuff before this will be removed
services.AddSingleton<ILoggerProvider>(serviceProvider =>
{
ServiceLocator.ServiceProvider = serviceProvider;

NLogBuilder.RegisterNLogWebAspNetCore();

LogManager.Configuration?.Reload();
return new NLogLoggerFactory(options);

return new NLogLoggerProvider(options);
});

//note: this one is called before services.AddSingleton<ILoggerFactory>
if (options.RegisterHttpContextAccessor)
{
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
}

});

return builder;
}



});
return builder;
}
#endif


Expand Down

0 comments on commit d0aee5c

Please sign in to comment.