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 application (vb.net). It works on my computer, but it gives an error when starting from IIS 6. 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 I received is:

 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() 

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

In fact, the Microsoft Corporation\Internet Information Services\6.0.3790.3959 does not exist inside the Default User\Application Data . I tried to create it by assigning full access to everyone, but I still have the same error.

Can I use Microsoft.VisualBasic.Logging.FileLogTraceListener from an ASP.NET MVC application?

+6
source share
4 answers

Sorry, my mistake!

I added C:\Documents and Settings\Default User\Application Data\Microsoft Corporation\Internet Information Services\6.0.3790.3959 to another server. After I added \Microsoft Corporation\Internet Information Services\6.0.3790.3959 to the desired server and granted it write access, the log works.

+3
source

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

  • changing the path in which it will write / log
  • run with an account with access to the path
  • give the IIS user access to the path that is trying to write to
+1
source

This error occurs because the FileLogTraceListener constructor tries to get the "current" application data folder. Current for IIS6 — How the user works by default. Then, since the folder does not exist, it (the code that it actually calls) tries to create it.

He tries to get the application data folder so that he can initialize his own EVEN location property if you specify it in the web.config file and therefore he really doesn’t need it. Pretty dumb design.

+1
source

Try marking the link as “Copy local” in visual studio, and then rebuild. I feel that the identity of your AppPool is working, it does not have read access to the referenced DLL.

0
source

Source: https://habr.com/ru/post/899457/


All Articles