LogFactory - KeepVariablesOnReload = true by default for config variables#4240
LogFactory - KeepVariablesOnReload = true by default for config variables#4240
Conversation
9f48797 to
cd6c628
Compare
|
@304NotModified Not the smallest PullRequest for changing a default-value. But I find it important that NLog Config Variables behaves in a predictable manner, where only NLog Config Variables that have been modified by API are kept on reload. |
|
The description sounds good! |
|
I'm fine with this enabled by default. I haven't checked the code yet. |
3d24249 to
3632a2b
Compare
|
Close and reopening to trigger rebuild |
…bles assigned from API
3632a2b to
5fc6fa9
Compare
|
Restarted azure pipeline |
|
Green! |
|
Yeah! Looking forward to remove warnings and caveats from the docs.
|
| private readonly ThreadSafeDictionary<string, Layout> _variables = new ThreadSafeDictionary<string, Layout>(StringComparer.OrdinalIgnoreCase); | ||
| private readonly LoggingConfiguration _configuration; | ||
| private ThreadSafeDictionary<string, Layout> _dynamicVariables; | ||
| private ThreadSafeDictionary<string, bool> _apiVariables; |
There was a problem hiding this comment.
Aren't those then the "const variables"?
There was a problem hiding this comment.
_dynamicVariables are those used by ${var} and const-variables. _apiVariables are those assigned using LoggingConfiguration.Variables-dictionary
…bles assigned from API (code review fixed)
|
Kudos, SonarCloud Quality Gate passed! |
|
Updated wiki: https://github.com/NLog/NLog/wiki/Configuration-file with KeepVariablesOnReload=true by default |
Resolves #2509 and resolves #2960
The old way triggered variable-restore AFTER having loaded the new config from file. It would restore ALL values from the old config (Thus discarding any updates made in the new config files). And at the same time prevents static-mode variables from working with config-variables assigned from API.
The new way triggers variable-restore BEFORE starting to load the new file. It will ONLY restore config-variables that has been assigned from the API by using
LoggingConfiguration.Variables-property.The new way will work automatically when manually calling
XmlLoggingConfiguration.Reload(), instead of only when file-watcher detects file-changes and triggers special reload.The new way will also automatically add extra protection for NLog-Config-Variable-Layout that is not ThreadSafe by default (Rare case). Thus removing the possible issue with thread-safety and NLog-Config-Variables.
${var}or when assigned as const-Layout.