I need to check whether NLog section exists in my app.config and add it if it doesn't.
The app.config should contain a simple NLog configuration like
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
<variable name="myvar" value="myvalue" />
<variable name="globalLevel" value="debug" />
<targets async="true">
<target name="logfile" xsi:type="File" fileName="${basedir}/logs/${shortdate} mylogfile ${environment:COMPUTERNAME}.log" />
</targets>
<rules>
<logger name="*" minlevel="${globalLevel}" writeTo="logfile" layout="${longdate} ${level} ${message}" />
</rules>
I cannot seem to find a method in NLog API which writes to config file. I can load the Config in many ways, for example
var config = new NLog.Config.XmlLoggingConfiguration("NLogTest.exe.config");
Then I can add/modify the config adding targets, rules, etc., but how do I write it to my config file?