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

user2023861 picture user2023861 · Nov 5, 2014 · Viewed 9k times · Source

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.

Answer

nemesv picture nemesv · Nov 5, 2014

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.