Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nlog not creating file relative to website project

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?

like image 865
FarFigNewton Avatar asked May 16 '12 14:05

FarFigNewton


People also ask

How do I add a NLog to my project?

Alternatively, you can install NLog using the NuGet Package Manager. To do this, all you need to do is create a project in Visual Studio, right-click on the project in the Solution Explorer window, and then select the “Manage NuGet Packages...” option. Next, you can select NLog.

What is Basedir in NLog?

${basedir} — Directory where the application runs, aka. AppDomain.BaseDirectory.

What can be configured with this NLog config file?

The following types can be configured: Targets - the destinations of a logevent, e.g. file, database, console. Layout - the layout e.g. json, csv, plain-text (default) Layout renderers - the template markers, e.g. ${message}, ${exception}, ${date}


1 Answers

We figured it out.

Add ${basedir} to the filename

filename="${basedir}/log.txt" 
like image 51
FarFigNewton Avatar answered Sep 29 '22 07:09

FarFigNewton