asp.net-mvc-3 - 将 Microsoft.VisualBasic.Logging.FileLogTraceListener 与 ASP.NET MVC 3 结合使用

标签 asp.net-mvc-3 logging system.diagnostics

我正在尝试在我的 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/

相关文章:

nhibernate - 你应该如何在我的 asp.net-mvc 站点上使用 UnitofWork 模式(使用 nhibernate 和 ninject)

java - Logback 文件附加程序不会立即刷新

c# - 如何找到事件的(使用中的)图形卡? C#

如果使用 <a>,javascript 不会向处理程序提交数据

asp.net-mvc - 使用 JSON 返回 Razor 部分 View (ASP MVC 3)

python - 如何使用 Python 日志记录模块显示日期格式

mono - Mono 中的 System.Diagnostics.Tracing

c# - Process.Start 参数不起作用

c# - 您必须指定一个有效的 JavaScript API 域作为此 key 配置的一部分。在领英

svn - 如何在IntelliJ中查看Svn详细日志