-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move NLog config into appsettings.json, or alternatively, add extension method for ConfigurationBuilder to load NLog config #29
Comments
Can you elaborate on this? We prefer moving to json but everything is on hold as we are waiting for rc2 of Microsoft. useful links: |
I think I can elaborate. It should be possible to do this: https://github.com/nlog/NLog/wiki/Configuration-API This method only allows loading from XML file:
We should add a method to load from a LoggingConfiguration as well: And possibly add another extension that can load from appsettings.json |
Well you can use |
I like to work on this, but it's a bit unclear to me what the extension method on ConfigurationBuilder should do |
are you still looking for help on this? I could possibly do this for you |
Yes, that would be great! |
closing this in favor of NLog/NLog#1588
This one is available currently |
I know the discussion in moved to NLog/NLog#1588 but a different solution to consider is giving the A relevant example for this solution for this Issue #29 would having something like this in // where the NLogConfigSection class implements NLog.Config.IConfiguration
var nLogConfigSection = Configuration.GetSection("Logging:NLog:Config")
.Get<NLogConfigSection>();
var nLogConfig = new NLog.Config.LoggingConfiguration(nLogConfigSection);
NLog.LogManager.Configuration = nLogConfig; There could even be a basic class implementing |
@MacKinley I like that LoggingConfiguration is simple and doesn't include a parser of configuration. You are welcome to review NLog/NLog#2891 and come with ideas for how to improve the interface of LoggingConfigurationParser (That can load configuration from When NLog 4.6 is out then I will release a PullRequest for NLog.Extensions.Logging that makes it possible to load config from appsettings.json |
Created #263 for people who would like to test NLog-config from |
@snakefoot I checked out #263 and like where you're headed, but I'm wondering if you're doing ".AddJsonFile(...)" and passing "appsettings.json", how would we be able to handle a scenario where we deploy to multiple environments (with different settings needed for log level, file path, etc...) and have a "appsettings.Development.json" and "appsettings.Staging.json"? Is there another way you would recommend handing this? Thanks |
@joegithub I'm probably one of the worst persons to ask about how to configure NetCore-application using appsettings.json. Never developed any NetCore applications besides console test-applications. But I have seen code that merges multiple appsettings-files like this:
This should merge the settings from the different appsettings.json files. Not sure if it makes sense to "merge" nlog-config-sections together. But you have the option to reference parameters from a different section (Ex. connectionstring-parameters) using the NLog ${configsetting} Ex. The environment-specific parameters could then be placed in the environment-specific-file (Ex. appsettings.Production.json), and be merged into the official configuration. |
NLog.Extension.Logging ver. 1.5.0 have now been released with support for NLog-config in appsettings.json: https://www.nuget.org/packages/NLog.Extensions.Logging Wiki: https://github.com/NLog/NLog.Extensions.Logging/wiki/Json-NLog-Config |
@joegithub Looks like you are not the only one that likes to merge appsettings-files together depending on environment. If you have any input then you can raise it here: #293 |
.config files have been mostly dropped from .net core, in favour of the appsettings.json file. Sections can be added to the file, and read into a strongly typed class used in your configuration (example http://www.codeproject.com/Tips/1005242/Using-nLog-with-ASP-NET-vNext). Alternatively you could keep the .config file, and add an extension method for ConfigurationBuilder, to automatically read and process it. However then you would need to get the NLog config from the IConfigurationRoot I believe (still checking this part out).
The text was updated successfully, but these errors were encountered: