{"action":"created","issue":{"url":"https://api.github.com/repos/NLog/NLog.Extensions.Logging/issues/252","repository_url":"https://api.github.com/repos/NLog/NLog.Extensions.Logging","labels_url":"https://api.github.com/repos/NLog/NLog.Extensions.Logging/issues/252/labels{/name}","comments_url":"https://api.github.com/repos/NLog/NLog.Extensions.Logging/issues/252/comments","events_url":"https://api.github.com/repos/NLog/NLog.Extensions.Logging/issues/252/events","html_url":"https://github.com/NLog/NLog.Extensions.Logging/issues/252","id":369179604,"node_id":"MDU6SXNzdWUzNjkxNzk2MDQ=","number":252,"title":"ILoggerFactory can't be configured from the ILoggingBuilder?  And static methods?","user":{"login":"jholovacs","id":1767540,"node_id":"MDQ6VXNlcjE3Njc1NDA=","avatar_url":"https://avatars0.githubusercontent.com/u/1767540?v=4","gravatar_id":"","url":"https://api.github.com/users/jholovacs","html_url":"https://github.com/jholovacs","followers_url":"https://api.github.com/users/jholovacs/followers","following_url":"https://api.github.com/users/jholovacs/following{/other_user}","gists_url":"https://api.github.com/users/jholovacs/gists{/gist_id}","starred_url":"https://api.github.com/users/jholovacs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jholovacs/subscriptions","organizations_url":"https://api.github.com/users/jholovacs/orgs","repos_url":"https://api.github.com/users/jholovacs/repos","events_url":"https://api.github.com/users/jholovacs/events{/privacy}","received_events_url":"https://api.github.com/users/jholovacs/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-10-11T15:32:26Z","updated_at":"2018-10-11T20:39:05Z","closed_at":null,"author_association":"NONE","body":"I inject `ILoggerFactory` into my classes and create the `ILogger` in them; nice and abstracted, very loosely coupled, just the way I like.\r\n\r\nBut I'm a little frustrated with the hoops I have to go through in my .NET Core apps to get NLog to work with `ILoggerFactory`... it's a very late binding, where I have to get my `ILoggerFactory` instance through my IoC container, and _then_ add the NLog components:\r\n\r\n```csharp\r\nLogManager.LoadConfiguration(\"nlog.config\");\r\nLogManager.Configuration.Variables[\"appDbConnectionString\"] = DatabaseContextConfiguration.ConnectionString;\r\nvar loggerFactory = app.ApplicationServices.GetService<ILoggerFactory>();\r\nloggerFactory.AddNLog();\r\n```\r\n\r\nOne frustration I'm having is the static methods on `LogManager`... as a general rule, static methods like this become impossible to play with when unit testing, and it seems unnecessary.  Can't we attach these values to an instance of the class rather than the class itself? \r\n\r\nAdditionally, I'm losing a lot of valuable logging in the startup and initializing of my application like this, because this binding occurs after all my dependency injection has been configured.  I can't log anything to my db log through NLog until the `ILoggerFactory` has been properly configured.\r\n\r\nCan we allow a method off the ILoggingBuilder (invoked through `IServiceCollection.AddLogging(ILoggingBuilder => { })`) to scaffold up the ILoggerFactory for use with NLog at this time?  I'm imagining an implementation like:\r\n\r\n```csharp\r\nservices.AddLogging(builder =>\r\n{\r\n\tbuilder.AddNLog(\"nlog.config\");\r\n\tbuilder.AddNLogVariable(\"appDbConnectionString\",\r\n\t\tioc => ioc.ServiceProvider.GetService<IConfiguration>()[\"ConnectionStrings:LoggingContext\"]);\r\n\tbuilder.AddNLogLoggerFactory();\r\n});\r\n```\r\nIf we can do this first thing in the Startup.cs class, we get access to a lot more stuff, and it seems like a much cleaner interface."},"comment":{"url":"https://api.github.com/repos/NLog/NLog.Extensions.Logging/issues/comments/429110191","html_url":"https://github.com/NLog/NLog.Extensions.Logging/issues/252#issuecomment-429110191","issue_url":"https://api.github.com/repos/NLog/NLog.Extensions.Logging/issues/252","id":429110191,"node_id":"MDEyOklzc3VlQ29tbWVudDQyOTExMDE5MQ==","user":{"login":"304NotModified","id":5808377,"node_id":"MDQ6VXNlcjU4MDgzNzc=","avatar_url":"https://avatars1.githubusercontent.com/u/5808377?v=4","gravatar_id":"","url":"https://api.github.com/users/304NotModified","html_url":"https://github.com/304NotModified","followers_url":"https://api.github.com/users/304NotModified/followers","following_url":"https://api.github.com/users/304NotModified/following{/other_user}","gists_url":"https://api.github.com/users/304NotModified/gists{/gist_id}","starred_url":"https://api.github.com/users/304NotModified/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/304NotModified/subscriptions","organizations_url":"https://api.github.com/users/304NotModified/orgs","repos_url":"https://api.github.com/users/304NotModified/repos","events_url":"https://api.github.com/users/304NotModified/events{/privacy}","received_events_url":"https://api.github.com/users/304NotModified/received_events","type":"User","site_admin":false},"created_at":"2018-10-11T20:39:05Z","updated_at":"2018-10-11T20:39:05Z","author_association":"MEMBER","body":"> I think the reason why `AddNLog(this ILoggingBuilder factory)` doesn't have the ability to receive NLog-configuration as input is because many wanted the NLog-logging available before anything else.\r\n\r\nPS: AddNLog is for setting up the DI, and not for configuring components. Those are separated in ASP.NET Core 1"}}
{"actor":{"display_login":"304NotModified"}}