我正在尝试在我的 ASP.NET MVC 3 应用程序 (vb.net) 中使用 Microsoft.VisualBasic.Logging.FileLogTraceListener。它可以在我的开发 PC 上运行,但从 IIS 6 服务器运行时会抛出错误。这是我使用的 web.config:
<?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>
我得到的错误是这样的:
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()
看起来 FileLogTraceListener 尝试写入 C:\Documents and Settings\Default User\Application Data\Microsoft Corporation\Internet Information Services\6.0.3790.3959
但失败。
实际上,Default User\Application Data
中不存在文件夹 Microsoft Corporation\Internet Information Services\6.0.3790.3959
。我尝试创建它,为每个人分配完全访问权限,但我仍然遇到相同的错误。
是否可以从 ASP.NET MVC 应用程序使用 Microsoft.VisualBasic.Logging.FileLogTraceListener?
最佳答案
非常抱歉,我的错误!
我在不同服务器上添加了C:\Documents and Settings\Default User\Application Data\Microsoft Corporation\Internet Information Services\6.0.3790.3959
。在正确的服务器上添加 \Microsoft Corporation\Internet Information Services\6.0.3790.3959
并授予对其写入访问权限后,日志记录正常工作。
关于asp.net-mvc-3 - 将 Microsoft.VisualBasic.Logging.FileLogTraceListener 与 ASP.NET MVC 3 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7793562/