.netapp-confignlognlog-configuration

Is there a way to put NLog.config information inside of my app.config file?


Is there a way to put NLog.config information inside of my app.config file? This way I can have one config file instead of two. It could look like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="nlog" type="..." />
  </configSections>
  <nlog>
    <targets>...</targets>
    <rules>...</rules>
  </nlog>
</configuration>

Please let me know if this is a duplicate.


Solution

  • Of course that you can put the configuration in your app.config file.

    You just need to use the NLog.Config.ConfigSectionHandler so you need to write

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
        <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
      </configSections>
      <nlog>
        <targets>...</targets>
        <rules>...</rules>
      </nlog>
    </configuration>
    

    as described in the NLog documentation in the Configuration file format section.