I have multiple applications that share a config file that sets up NLog partially looking something like this
<targets>
<target name="eventlog" type="EventLog" source="ApplicationX" log="Application"
layout="${date}: ${message} ${stacktrace}" />
</targets>
The only difference that we need for each application is changing the source
What i have tried doing is at the start of each applications in the top Main setting
var target = ((EventLogTarget) _logger.Factory.Configuration.FindTargetByName("eventLog"));
target.Source = "Application1";
This seems to have had no effect on the log output.
Is there any programatic way to make tweaks like this to the settings of NLog?
Is there any other way to manage small changes in NLog config without having to keep different versions of full config files for each application?
You should get instance of Configuration from LogManager instead of logger’s factory:
More information about NLog runtime configuration you can found in documentation for NLog Configuration API