-
Notifications
You must be signed in to change notification settings - Fork 165
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
LogManager.Setup() - LoadConfigurationFromAppSettings #540
Conversation
08b114f
to
0a44432
Compare
Notice this is proof-on-concept and should not be merged, since it will bump to NLog 4.7 NLog.Extensions.Logging ver. 1.6.3 should be released first. Maybe after NLog 4.7.1 has been released. And then NLog.Web.AspNetCore can update its dependency, and then this can be merged. |
I have my doubts about having two extension methods with the same name but different namespaces:
Both methods does the same, but NLog.Web has the additional logic that it automatically registers NLog.Web-extensions before loading the NLogConfig. But I think confusion in tutorials may occur, and also confusion when right-clicking the method to fix missing usings (Will show two possible namespaces to include). But the same issue is also present with AddNLog and UseNLog, so I guess it is ok. |
Have to think about it. It could be confusing, maybe there is a better solution. |
What about LoadNLogConfigFromSectionWithWebIntegration? (so something like that?) |
Sounds like an awful name. Then prefer the name collission that also exists with AddNLog and UseNLog |
Codecov Report
|
What about doing this in NetCore2 (Introducing
Of course this means people have to remember two method-calls when in "legacy-mode". Or just want it flexible. Could also consider removing
When using NetCore3 (where all bells and whistles are available):
|
Agree, but that even better to me than a collision ;) (no joke). |
Sounds good! (update: or maybe AddNLogWeb, to get rid of 2 setups?) PS: for readability, I prefer newlines in those examples So instead of var logger = NLog.LogManager.Setup(). SetupNLogWeb().LoadNLogConfigFromSection(config).LogFactory.GetCurrentClassLogger(); this: var logger = NLog.LogManager
.Setup()
.SetupNLogWeb()
.LoadNLogConfigFromSection(config)
.LogFactory
.GetCurrentClassLogger(); PS2: maybe stupid question, but we can't get rid if |
We can easily add a GetCurrentClassLogger()-extension-method to the ISetupBuilder-interface. Not sure what you mean about removing |
969632c
to
b4e202f
Compare
19d27e8
to
6c1cb1b
Compare
@304NotModified Have added unit-tests for the new method |
e3fda18
to
7549c4f
Compare
Thanks I think that coverage is only for one platform (merge same code base for multiple platforms is always difficult, also in terms of performance) |
1c98688
to
2f5d960
Compare
Is this ready to review? (Unexpected force pushes :)) |
Yes ready now. Just wanted to add |
Kudos, SonarCloud Quality Gate passed! 0 Bugs |
Thanks! Merged! |
Now you can do this in NetCore3:
And it replaces this for NetCore3 (Could consider making it obsolete):
And also configures ${configsetting} and also checks appsetting.json if it contains a NLog-section with NLog config. But if none found, then NLog automatic load of NLog.config takes over.
For NetCore2 then one can do this instead of
NLogBuilder.ConfigureNLog
:This PR is a proof-of-concept, and should be delayed until NLog.Extension.Logging has been released with NLog 4.7 (Or maybe NLog 4.7.1)