Reputation: 3496
I'm trying to log some application info using NLog 4.4.12
But I can't seem to create the log file in my C drive
.
I have a class library running on .net 4.6.1
I have created an NLog.config
in the root directory of that project.
<?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">
<targets>
<target name="logfile" xsi:type="File" fileName="c:\ApiLogfile.txt" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logfile" />
</rules>
</nlog>
When I call logger.Info("NLog to the rescue")
the output file isn't created in the C drive. Am I missing something here?
Upvotes: 2
Views: 919
Reputation: 154
I can't get it to work using
<target name="logfile" xsi:type="File" fileName="c:\ApiLogfile.txt" />
This is probably a permissions issue and if you execute the application as Administrator it does work.
These two locations worked for me:
<target name="logfile" xsi:type="File" fileName="${basedir}/ApiLogfile.txt" />
<target name="logfile" xsi:type="File" fileName="C:\Users\{username}\Documents\ApiLogfile.txt" />
Also ensure the Copy to Output Directory is set to Copy always for the NLog.config file to ensure it is copied to the output directory, which is where NLog assembly expects it to be.
Upvotes: 1