Nlog not creating file relative to website project

FarFigNewton picture FarFigNewton · May 16, 2012 · Viewed 9.1k times · Source

I am using a website project, I added Nlog from Nuget, and used the following NLog configuration :

<?xml version="1.0" encoding="utf-8" ?>
<nlog autoReload="true" 
      throwExceptions="true" 
      xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <targets>
        <target name="logfile" xsi:type="File" fileName="log.txt" />
    </targets>

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

I ran ProcessMonitor and it shows that Nlog is trying to create log.txt in the IISExpress folder instead of my website project folder.

C:\Program Files (x86)\IIS Express\log.txt

How can I make NLog put my log file, log.txt, in my website project's folder instead of the IISExpress folder?

Answer

FarFigNewton picture FarFigNewton · May 16, 2012

We figured it out.

Add ${basedir} to the filename

filename="${basedir}/log.txt"