JuChom
JuChom

Reputation: 5989

NLog internal log not working with ASP.Net MVC

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?

Upvotes: 14

Views: 14299

Answers (4)

kolbasov
kolbasov

Reputation: 1588

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.

Upvotes: 12

Rolf Kristensen
Rolf Kristensen

Reputation: 19867

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

Upvotes: 1

Ed Spencer
Ed Spencer

Reputation: 462

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

Upvotes: 5

Willy
Willy

Reputation: 1729

from this link I think the path is absolute

Upvotes: 0

Related Questions