Exception in ASP.NET When Writing to File-Based Log

469 views
Skip to first unread message

Patrick Skelton

unread,
Feb 18, 2013, 1:14:02 PM2/18/13
to nlog-...@googlegroups.com
Hi,

I have just tried to set up NLog in an ASP.NET 4 application.  I followed the tutorial, and have set up what I believe is the simplest example I can.  Now, when I run the application, I get the following exception:

System.Web.HttpException occurred
 
Message=Invalid file name for file monitoring: 'D:\Data\Work\Dev\Projects\Live\FourthWish\WritingWebsite\controls'. Common reasons for failure include:
- The filename is not a valid Win32 file name.
- The filename is not an absolute path.
- The filename contains wildcard characters.
- The file specified is a directory.
- Access denied.
 
Source=System.Web
 
ErrorCode=-2147024809
 
WebEventCode=0
 
StackTrace:
       at
System.Web.DirectoryMonitor.AddFileMonitor(String file)
 
InnerException:



The failure is indeed one of the suggested reasons: the file name for monitoring is a directory.  But I have no idea what is trying to make this call.  Even more mysterious is that the directory on which monitoring is being attempted is a subfolder where I store ASP.NET user controls, and I certainly have not used this as a path anywhere in NLog's configuration.

My config is as follows:

<targets>
<target name="Standard" xsi:type="File" fileName="${basedir}/StandardLog.txt" layout="${longdate}|${message}" />
</targets>

<rules>
<logger name="*" minlevel="Trace" writeTo="Standard" />
</rules>

Can anyone offer any advice about what might be going on here and how I can begin debugging it. Any advice at all would be very much appreciated.

Kind wishes ~ Patrick



Kim Christensen

unread,
Feb 19, 2013, 7:09:37 PM2/19/13
to nlog-...@googlegroups.com
Hi Patrick,

What tutorial did you follow? Could you post you're full configuration?

Regards Kim

Patrick Skelton

unread,
Feb 20, 2013, 2:15:53 PM2/20/13
to nlog-...@googlegroups.com
Hi,

The tutorial is the one on here: https://github.com/nlog/nlog/wiki/Tutorial

My full config file contains little more than the bit I already posted.

<?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="Standard" xsi:type="File" fileName="${basedir}/StandardLog.txt" />

 
</targets>
 
<rules>
 
<logger name="*" minlevel="Trace" writeTo="Standard" />
 
</rules>
</nlog>


The application is ASP.NET 4 and is running on local IIS in a directory where I have full (Administrator) permissions.

Kind wishes, Patrick

Kim Christensen

unread,
Feb 21, 2013, 4:58:39 AM2/21/13
to nlog-...@googlegroups.com
I'll try to reproduce the error

Kim Christensen

unread,
Feb 26, 2013, 1:47:54 PM2/26/13
to nlog-...@googlegroups.com
I tried to create a simple ASP.NET 4 application, but everything works as it should. Could you post a sample project where the error appears on you side?

Patrick Skelton

unread,
Feb 27, 2013, 3:17:56 PM2/27/13
to nlog-...@googlegroups.com
Hi, Kim,

Unfortunately, I have now had to remove NLog from my main project, because I just couldn't spend any more time trying to get it working.

I tried creating a new ASP.NET website, and added NLog to it.  This worked when I had the project configured to debug on the inbuilt IIS server, but failed when I tried to get it to run on my full local IIS, so I am guessing that there is some kind of a permissions problem or some other configuration issue in IIS.  My main problem is that I can't debug this because even when I set internalLogToConsole="true" throwExceptions="true" in NLog, it still fails silently.

Only when I get the debugger to stop on all exceptions can I get some kind of idea what is failing.  Doing this, I have just tried to stop on all thrown exceptions in the new project and I get the debugger stopping to ask the location of the following file: c:\NLogBuild\src\NLog\Internal\FileAppenders\BaseFileAppender.cs.  If I get the debugger to continue, I do indeed get an UnauthorizedAccessException in BaseFileAppender.CreateWindowsFile.  I don't understand this, though, because I have full Administrator privileges in the directory and Visual Studio is running as Administrator.  I can fix this by adding IIS_IUSRS and giving this group full control.  Guess I can do this and simply pray that, when I deploy to the live server, I don't get the same problems.

In summary, I am sure the problem is caused by my lack of IIS knowledge, and not NLog, though it is disappointing that I can't get error information out of NLog without using the debugger in 'big hammer' mode.

Thank you for looking at this for me.


Kind wishes ~ Patrick


--
You received this message because you are subscribed to the Google Groups "NLog-Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nlog-users+...@googlegroups.com.
To post to this group, send email to nlog-...@googlegroups.com.
Visit this group at http://groups.google.com/group/nlog-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages