question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to change target URI after it is been read from NLog.config

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:22 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
snakefootcommented, May 9, 2019

@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

1reaction
snakefootcommented, May 9, 2019

The issue with reset of variables on reload. Is the reason why I’m suggesting the use of GDC.

Read more comments on GitHub >

github_iconTop Results From Across the Web

logging - c#, Nlog and change target
This line will load the NLog.config and lookup a named target: target = LogManager.Configuration.FindTargetByName("eventlog");.
Read more >
NLog 5.0 - List of major changes
When InitializeTarget() fails because of unresolved dependency, then NLog will automatically retry when expected type becomes available in the ...
Read more >
NLog Tutorial - The essential guide for logging from C#
The ultimate tutorial for NLog. Learn about everything from logging and structured log messages to layout renderers and configuration of ...
Read more >
Introduction to NLog
The configuration file is read automatically at program startup. In a long running process (such as a Windows service or an ASP.NET application) ......
Read more >
Internet Marketing Tips-Let - Google Books Result
I don't think it has been updated for a while, but anyway it works fine even on my WP 2.9 blog. ;) If...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found