6

I am trying to use Microsoft.VisualBasic.Logging.FileLogTraceListener in my ASP.NET MVC 3 app (vb.net). It works in my dev PC but throws an error when run from an IIS 6 server. Here is the web.config that I use:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.diagnostics>
        <trace autoflush="true" />
        <sources>
            <source name="requests" switchValue="All">
                <listeners>
                    <remove name="default" />
                    <add name="txtfile" />
                </listeners>
            </source>
        </sources>
        <sharedListeners>
            <add name="txtfile" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, 
                      Microsoft.VisualBasic, Version=8.0.0.0, 
                      Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, 
                      processorArchitecture=MSIL"
                 location="custom"
                 customlocation="D:\PROJECTS\saidproject\App_Data"
                 logfilecreationschedule="weekly"
            />
        </sharedListeners>
    </system.diagnostics>
</configuration>

The error that I got is this:

System.Configuration.ConfigurationErrorsException: Could not create Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL. ---> System.UnauthorizedAccessException: Access to the path 'C:\Documents and Settings\Default User\Application Data\Microsoft Corporation\Internet Information Services\6.0.3790.3959' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj)
   at System.IO.Directory.CreateDirectory(String path)
   at System.Windows.Forms.Application.GetDataPath(String basePath)
   at System.Windows.Forms.Application.get_UserAppDataPath()
   at Microsoft.VisualBasic.Logging.FileLogTraceListener..ctor(String name)
   at Microsoft.VisualBasic.Logging.FileLogTraceListener..ctor()

Looks like FileLogTraceListener tried to write to C:\Documents and Settings\Default User\Application Data\Microsoft Corporation\Internet Information Services\6.0.3790.3959 and failed.

Actually the folder Microsoft Corporation\Internet Information Services\6.0.3790.3959 doesn't exist within Default User\Application Data. I tried creating it, assigning full access to everyone, but I still got the same error.

Is it possible to use Microsoft.VisualBasic.Logging.FileLogTraceListener from ASP.NET MVC app?

Endy Tjahjono
  • 24,120
  • 23
  • 83
  • 123

4 Answers4

3

So sorry all, my mistake!

I added C:\Documents and Settings\Default User\Application Data\Microsoft Corporation\Internet Information Services\6.0.3790.3959 on a different server. After I added \Microsoft Corporation\Internet Information Services\6.0.3790.3959 on the right server and granting write access to it, the logging works.

Endy Tjahjono
  • 24,120
  • 23
  • 83
  • 123
1

Your application is probably running in IIS 6 under an account that does not have enough access to the path that is trying to write. Try

  • changing the path where it will write/log
  • run with an account that has access to the path
  • give access to the IIS user to the path that is trying to write to
Hector Correa
  • 26,290
  • 8
  • 57
  • 73
1

This error happens because the constructor for FileLogTraceListener tries to get the "current" application data folder. "Current" for IIS6 some how works out to default user. Then since the folder does not exist, it (the code it calls really) tries to create it.

It is trying to get the app data folder so it can initialize its custom location property EVEN if you've specified one in the web.config and thus is won't really need it. Pretty silly design.

Tom Winter
  • 1,813
  • 3
  • 18
  • 23
0

Try to mark the reference as "Copy Local" in visual studio, then rebuild. My gut feeling is that the identity your AppPool runs under does not have access to read the reference dll.

Christian Wattengård
  • 5,543
  • 5
  • 30
  • 43
  • I think it's inside Microsoft.VisualBasic. Isn't it already included by default? I'm using vb.net – Endy Tjahjono Oct 17 '11 at 12:44
  • It is, but I think that if you mark it Copy Local, it will make a copy of it in your "bin" folder. Which could solve problems related to rights. – Christian Wattengård Oct 17 '11 at 13:11
  • The location being accessed is pretty clear here, and does not at all indicate problems accessing the assembly in question. I would not take this particular advice. – Andrew Barber Oct 17 '11 at 13:54