Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Microsoft.VisualBasic.Logging.FileLogTraceListener with ASP.NET MVC 3

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?

like image 288
Endy Tjahjono Avatar asked Oct 17 '11 12:10

Endy Tjahjono


2 Answers

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.

like image 156
Endy Tjahjono Avatar answered Sep 28 '22 01:09

Endy Tjahjono


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
like image 22
Hector Correa Avatar answered Sep 28 '22 03:09

Hector Correa