Search code examples
asp.net-mvcnlog

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?


Solution

  • 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.