LogParser 在 WebApp 中失败

发布于 2024-08-07 20:11:12 字数 1256 浏览 6 评论 0原文

我开发了一个 WinForms 应用程序,它使用 LogParser 显示单个 IIS 站点的带宽。这非常有效。

我现在在 ASP.net 中编写了完全相同的内容,但随后引发了以下异常: 找不到任何与“C:\inetpub\logs\LogFiles\W3SVC4\ex*.log”匹配的文件

该异常是有道理的,因为我们所有的日志文件都以“u_ex”而不是“ex”为前缀(我猜是默认的 IIS 设置) 。奇怪的是,它在从 WinForms 应用程序运行时确实有效,而在放入 WebApp 中时却无效。

有谁知道为什么会发生这种情况以及我该如何解决它?

谢谢!

这是我正在使用的代码的一部分:

private void UpdateByDateRange(DateTime dateFrom, DateTime dateTo) 
{

string siteId = Request.ServerVariables["INSTANCE_ID"]; 
LogQueryClassClass logger = new LogQueryClassClass();

COMIISW3CInputContextClass inputContext = new COMIISW3CInputContextClassClass(); 
string query = "SELECT SUM(TO_REAL(sc-bytes)) AS sentTotal, SUM(TO_REAL(cs-bytes)) AS receivedTotal FROM <" + siteId + "> WHERE TO_TIMESTAMP(date, time) >= TO_TIMESTAMP('" + dateFrom.ToString("yyyy-MM-dd HH:mm:ss") + "', 'yyyy-MM-dd HH:mm:ss') AND TO_TIMESTAMP(date, time) <= TO_TIMESTAMP('" + dateTo.ToString("yyyy-MM-dd HH:mm:ss") + "', 'yyyy-MM-dd HH:mm:ss')";

ILogRecord record = logger.Execute(query, inputContext).getRecord(); 
decimal trafficSent = decimal.Parse(record.getValue("sentTotal").ToString());

decimal trafficReceived = decimal.Parse(record.getValue("receivedTotal").ToString()); 
// ...

}

I've developed a WinForms app that I've that shows the bandwidth a single IIS site using LogParser. This worked quite well.

I've now written the exact same thing in ASP.net, but then the following exception is thrown:
Cannot find any file matching "C:\inetpub\logs\LogFiles\W3SVC4\ex*.log"

The exception makes sence, since all our log files are prefixed with 'u_ex' and not 'ex' (default IIS settings I guess). It's just strange that it does work when ran from a WinForms application and not when put in a WebApp.

Does anyone know why this happens and how I can fix it?

Thanks!

Here's a chuck of the code I'm using:

private void UpdateByDateRange(DateTime dateFrom, DateTime dateTo) 
{

string siteId = Request.ServerVariables["INSTANCE_ID"]; 
LogQueryClassClass logger = new LogQueryClassClass();

COMIISW3CInputContextClass inputContext = new COMIISW3CInputContextClassClass(); 
string query = "SELECT SUM(TO_REAL(sc-bytes)) AS sentTotal, SUM(TO_REAL(cs-bytes)) AS receivedTotal FROM <" + siteId + "> WHERE TO_TIMESTAMP(date, time) >= TO_TIMESTAMP('" + dateFrom.ToString("yyyy-MM-dd HH:mm:ss") + "', 'yyyy-MM-dd HH:mm:ss') AND TO_TIMESTAMP(date, time) <= TO_TIMESTAMP('" + dateTo.ToString("yyyy-MM-dd HH:mm:ss") + "', 'yyyy-MM-dd HH:mm:ss')";

ILogRecord record = logger.Execute(query, inputContext).getRecord(); 
decimal trafficSent = decimal.Parse(record.getValue("sentTotal").ToString());

decimal trafficReceived = decimal.Parse(record.getValue("receivedTotal").ToString()); 
// ...

}

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

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

发布评论

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

评论(1

思念满溢 2024-08-14 20:11:12

AspNet 是否有权访问 C:\inetpub\logs\LogFiles\W3SVC4\ 文件夹?当文件不存在或运行时没有权限时,通常会发生此错误。作为 Asp.Net 应用程序,您需要确保 AspNet 帐户有权访问此文件夹或在具有访问权限的另一个帐户下运行网站。

这篇旧文章可能会有所帮助。

ASPNET 用户没有写入权限临时 ASP.NET 文件

Does AspNet have permissions to the C:\inetpub\logs\LogFiles\W3SVC4\ folder? This error normally occurs when the file doesn't exist OR the runtime does not have permissions. As an Asp.Net app, you need to ensure that the AspNet account has access to this folder or run the web site under another account that does have access.

This older post might help.

ASPNET user does not have write access to Temporary ASP.NET Files

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