Miroslav Popov Miroslav Popov - 1 month ago 7x
C# Question

NLog via LINQPad - Where to put config file?

I'm trying to test NLog under LINQPad.

I successfully linked it and my code compiles well. However, NLog doesn't write log files because it is not configured.

I tried to make various config files like:

but it looks like I do not do it correctly.

My testing code under LINQPad is:

void Main()
int zero = 0;
int result = 5 / zero;
catch (DivideByZeroException ex)
Logger logger = LogManager.GetCurrentClassLogger();
logger.ErrorException("Whoops!", ex);

Config code:

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"

<target name="logfile" xsi:type="File" fileName="logfile.log" />

<logger name="*" minlevel="Info" writeTo="logfile" />

Where to put the config file?


Thanks to @pasty and @nemesv comments, the problem is fixed.

The config file must be named NLog.config and must be placed in the LINQPad.exe folder.

The log file (logfile.log in my case) appears in the same folder.

LINQPad needs write access to the folder in order to write the log file.

LINQPad must be restarted after setting the config file.


If you start LINQPad, load or write the code and run it, the log file appears in the LINQPad.exe folder.

If you run the code by clicking on saved code file like NLog Test.linq in my case, the log file appears in the folder of the code file. (C:\Users\Miroslav\Documents\LINQPad Queries in my case)