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?
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.
${basedir} — Directory where the application runs, aka. AppDomain.BaseDirectory.
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}
We figured it out.
Add ${basedir} to the filename
filename="${basedir}/log.txt"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With