将 Microsoft.VisualBasic.Logging.FileLogTraceListener 与 ASP.NET MVC 3 结合使用

发布于 2024-12-10 04:55:42 字数 2616 浏览 0 评论 0原文

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

短叹 2024-12-17 04:55:42

非常抱歉,我的错误!

我在不同服务器上添加了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 并授予对其写入访问权限后,日志记录可以正常工作。

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.

蔚蓝源自深海 2024-12-17 04:55:42

您的应用程序可能在 IIS 6 中运行的帐户没有足够的访问权限来访问尝试写入的路径。尝试

  • 更改写入/日志运行的路径
  • ,使用有权访问该路径的帐户
  • 授予 IIS 用户对尝试写入的路径的访问权限

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
(り薆情海 2024-12-17 04:55:42

发生此错误的原因是 FileLogTraceListener 的构造函数尝试获取“当前”应用程序数据文件夹。 IIS6 的“当前”默认用户的一些工作方式。然后,由于该文件夹不存在,它(它真正调用的代码)尝试创建它。

它正在尝试获取应用程序数据文件夹,以便即使您在 web.config 中指定了自定义位置属性,它也可以初始化其自定义位置属性,因此实际上并不需要它。相当愚蠢的设计。

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.

贪恋 2024-12-17 04:55:42

尝试在 Visual Studio 中将引用标记为“复制本地”,然后重建。我的直觉是,您的 AppPool 运行的身份无权读取引用 dll。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文