-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Control throwing of NLogConfigurationExceptions (LogManager.ThrowConfigExceptions) #1238
Conversation
169b9c6
to
6994f04
Compare
e8791a2
to
a65ef6a
Compare
Current coverage is
|
0761a6a
to
a8482f1
Compare
Assert.False() Failure |
@bhaeussermann I would like to have your opinion on this one :) |
@304NotModified This seems to be the best solution. I'm also happy with the code. However, what is going to happen if the configuration used is |
Thanks for the check!
It will throw runtime exceptions and not config exceptions.
Nice idea, but we like to throw less exceptions (by default!) because:
|
Control throwing of NLogConfigurationExceptions (LogManager.ThrowConfigExceptions)
My suggestion applied to this situation. What runtime exception would this throw? Would it be clear that something went wrong with configuration? I cannot check that right now. If it is not clear from that "runtime" exception, then perhaps we should add a check to throw a more meaningful exception for this situation telling the developer to check the internal log. |
(My comment above assumes the situation where there is an error in the configuration.) |
I'm not sure if we are on the same line. So we have now with the PR two properties:
All the exceptions get logged to the internal logger. ThrowExceptions was already in NLog (with default So it's indeed less clear when there is a config mistake now, but this PR will also lead to less errors at runtime (config mistake can be also at runtime when changing the config) and no unclear If you like the previous behavior, just change |
Added
ThrowConfigExceptions
to control throwing ofNLogConfigurationException
. BeforeNLogConfigurationException
where always thrown, which could lead toSystem.TypeInitializationException
which is bad and confusing as sending info with the exception is difficult - see stackoverflow.if
ThrowConfigExceptions
isnull
(or emptystring
from XML), thenThrowExceptions
is used. SoThrowConfigExceptions
inherits fromThrowExceptions
.This isn't fully backwards-compatible, but it is also a bug as we in code and docs is stated "By default exceptions are not thrown under any circumstances.". also this is a good change to include with #1143
With the addition of #1222, there is no good reason to throw exceptions even with config errors.