Unable to change target URI after it is been read from NLog.config
See original GitHub issueI am using NLog to write logs to ElasticSearch. I have defined the ElasticSearch target in the NLog.config file which looks like this:
<target name="defaultelastictarget" xsi:type="BufferingWrapper" bufferSize="10" flushTimeout="5000><target xsi:type="ElasticSearch" uri="http://localhost">
Now, after the NLog.config file is loaded to the LogManager, I need to programatically update Uri of this target. However, after I updated it by calling elasticSearchTarget.Uri = "new uri"
and then calling LogManager.ReconfigExistingLoggers()
, the log messages are not written to the ElasticSearch. It seems that the target is not reloaded and reinitialized with the new Uri.
The only way I managed to make it work is to construct new ElasticSearchTarget
instance for with the new Uri and completely remove the original target (defined in NLog.config) and replace with the new ElasticSearchTarget
instance I just created.
I am not sure if I am even correctly updating Uri of ElasticSearchTarget
, I did not managed to find any example of how to do it. It feels a bit excessive to destroy original target and create new one just for updating a single property.
Is this a valid issue or I was updating the Uri in the wrong way?
Issue Analytics
- State:
- Created 4 years ago
- Comments:22 (1 by maintainers)
@mindisk I have now created this wiki-page after seeing all the trouble you have been through:
https://github.com/NLog/NLog/wiki/Reinitialize-NLog-configuration
The issue with reset of variables on reload. Is the reason why I’m suggesting the use of GDC.