-
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
Skipping empty config sections without throwing exceptions #724
Conversation
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #724 +/- ##
==========================================
- Coverage 81.21% 81.18% -0.03%
==========================================
Files 19 19
Lines 1735 1743 +8
Branches 304 311 +7
==========================================
+ Hits 1409 1415 +6
+ Misses 189 188 -1
- Partials 137 140 +3 ☔ View full report in Codecov by Sentry. |
Thank you for the pull-request, and starting the idea-race. I guess it would work against the validation of unrecognized configuration-keys, as users might get confused why settings goes completely under the radar (ignored). Also curious what would happen with Maybe the handling of simple-values assigned to |
You have a valid concern :) |
test/NLog.Extensions.Logging.Tests/NLogLoggingConfigurationTests.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think it looks great. And thank you for the unit-tests.
Are you in a hurry and need a release right now? or are you fine with waiting ? |
No hurry at all 😄 This PR was a coding interview task for me 😄 Thanks for you time and guidance here @snakefoot 🙏 |
NLog.Extensions.Logging v5.3.9 has been released, that allows official sections like Thanks again for the contribution. |
This fixes NLog/NLog#5469
When config file has empty sections like this
Those sections are read as key-value pairs with
null
as the value.This causes an exception when
LoggingConfigurationParser
is trying to parse it. There is a whitelist of properties allowed in the config.The exception message is also a bit misleading
Unrecognized value 'targets'='' for element 'NLog'
In this PR I am checking if the "property" (which is actually an empty section) has no value. And if so - I am skipping it.
Added a test that blows up with exact same exception as the one described in the linked issue (before my changes). The test passes with the changes.
I had to add a dependency to
Microsoft.Extensions.Configuration.Json
to be able to pass JSON config as a string. But this is for the test project only, so I hope it is OK.