Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 241
JuChom Avatar asked Feb 24 '12 09:02

JuChom


2 Answers

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.

like image 123
kolbasov Avatar answered Sep 26 '22 19:09

kolbasov


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

like image 30
Ed Spencer Avatar answered Sep 22 '22 19:09

Ed Spencer