28

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.

user2023861
  • 8,030
  • 9
  • 57
  • 86

1 Answers1

38

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.

nemesv
  • 138,284
  • 16
  • 416
  • 359