14

I have a problem with NLog for logging its internal logs with this configuration

<?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"
  throwExceptions="true"
  internalLogFile="${basedir}/App_Data/NLog.log"
  internalLogLevel="Trace">

   <targets>
      <target name="debug"
              xsi:type="File" 
              fileName="${basedir}/App_Data/Site.log" />
   </targets>

   <rules>
      <logger name="*"
              writeTo="debug" />
   </rules>
</nlog>

The target "debug" is working well, but the internalLogFile is only working if I set it for exemple to "D:/NLog.log".

Any idea why this happening?

1
  • Note; the default path is where ever IISExpress is installed. If you specify: InternalLogFile="nLogError.txt". Then (at least on my PC) it will try and write to "C:\Program Files (x86)\IIS Express\nlogExceptions.txt". Which can have permission problems. Commented Apr 14, 2015 at 4:24

4 Answers 4

12

You can't use layout renderers ${...} in the internalLogFile property. They are for a target's layout only:

<target layout="${...}" />

Try to use relative path like "..\App_Data\NLog.log"

Update NLog 4.6 enables some simple layouts.

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for the answer. Relative path are not working, it seems that it needs absolute path.
you are wrong..i am using ${} in internal logging and it works fine!! @Swell u can use ${..} in internal log file
internalLogFile="${specialfolder:folder=CommonApplicationData}/Logs/Nlog/${shortdate}/Nlog-Internal.log"
Very good comment from a NLog collaborator on why this is not a good idea internalLogFile: NLog variables
for the record the comment mentioned was " 304NotModified commented on 18 Feb 2015 | As answered at Stackoverflow: this isn't possible and also unwanted. The internal logfile should be as stable as possible (a so no fancy features). Also I think thank the internal log should only be used in rare cases."
|
5

The internalLogFile attribute needs to be set to an absolute path and the executing assembly needs to have permission to write to that absolute path.

The following worked for me.

  1. Create a folder somewhere - e.g. the route of your c: drive, e.g. c:\logs
  2. Edit the permissions of this folder and give full control to everyone
  3. Set your nlog config: internalLogFile="C:\logs\nlog.txt"

Remember to clean up after yourself and not leave a directory with those sorts of permissions on

1 Comment

Thx for the tip. That worked for me. It appears that .NET Framework requires an absolute path, but ASP.NET Core allows for relative paths.
1

NLog ver. 4.6 add support for environment-variables like %appdata% or %HOME%, and using these basic layouts in internalLogFile=:

  • ${currentdir}
  • ${basedir}
  • ${tempdir}

NLog ver. 4.7 also adds this:

  • ${processdir}

See also: https://github.com/NLog/NLog/wiki/Internal-Logging

Comments

0

from this link I think the path is absolute

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.