NLog: Where is NLog Config?

Solution 1:

From NLog Wiki:

The following locations will be searched when executing a stand-alone *.exe application:

  • standard application configuration file (usually applicationname.exe.config)
  • applicationname.exe.nlog in application’s directory
  • NLog.config in application’s directory
  • NLog.dll.nlog in a directory where NLog.dll is located (only if NLog isn't installed in the GAC)

So, the easiest would be to add a NLog.config file in the application’s directory

Solution 2:

Sample Nlog.config File for your reference:

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      throwConfigExceptions="true">

    <targets>
        <target name="logfile" xsi:type="File" fileName="file.txt" />
        <target name="logconsole" xsi:type="Console" />
    </targets>

    <rules>
        <logger name="*" minlevel="Info" writeTo="logconsole" />
        <logger name="*" minlevel="Debug" writeTo="logfile" />
    </rules>
</nlog>

See also: https://github.com/NLog/NLog/wiki/Tutorial

Solution 3:

Alternatively you can define the config programmatically in C# as explained in the blog docs here: https://github.com/NLog/NLog/wiki/Configure-from-code