Using Microsoft.VisualBasic.Logging.FileLogTraceListener with ASP.NET MVC 3
Asked Answered
G

4

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?

Gallstone answered 17/10, 2011 at 12:12 Comment(0)
G
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.

Gallstone answered 17/10, 2011 at 13:55 Comment(0)
S
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
Seabury answered 17/10, 2011 at 13:24 Comment(0)
K
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.

Killarney answered 3/3, 2012 at 0:59 Comment(0)
P
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.

Positron answered 17/10, 2011 at 12:21 Comment(3)
I think it's inside Microsoft.VisualBasic. Isn't it already included by default? I'm using vb.netGallstone
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.Rangoon
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.Blabber

© 2022 - 2024 — McMap. All rights reserved.