编程检索IIS中的ASP.NET应用程序日志文件位置 [英] Programmatically retrieving IIS log file location in an ASP.NET application

查看:282
本文介绍了编程检索IIS中的ASP.NET应用程序日志文件位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想确定我的ASP.NET应用程序的IIS日志文件的位置的位置。我试过WMI,但无法找到它。有什么建议?

请注意:我希望能够以编程方式检索的位置;我为进一步利用应用程序中。
编辑:这是我的code:这工作,但并没有给我的日志的实际物理目录位置。因此,这是基本没用。

  ManagementPath P2 =新ManagementPath(IIsLogModule.Name ='日志/ Microsoft IIS日志文件格式);
日志的ManagementObject =新的ManagementObject(范围,P2,objectGet);
log.Get();
logPath.Text =日志[__ PATH]的ToString()。


解决方案

在IIS7你可以使用Microsoft.Web.Administration组装的网站类有一个名为属性<一个href=\"http://msdn.microsoft.com/en-us/library/microsoft.web.administration.sitelogfile_members%28v=vs.90%29.aspx\"相对=nofollow>日志文件,就可以得到有关的网站日志文件的各种信息,例如日志文件目录可以用此code获得:

  ServerManager的经理=新ServerManager的();
  网站MYSITE = manager.Sites [网站名称];
  的Response.Write(日志文件目录:+ mySite.LogFile.Directory +\\\\ W3SVC+ mySite.Id.ToString());

我不喜欢非常难codeD部分使用目录preFIX的网站,但没有发现任何其他更好的办法。

I'm trying to determine the location of the IIS log file location of my ASP.NET application. I tried WMI, but wasn't able to find it. Any suggestions?

Note: I want to be able to retrieve the location programmatically; inside my application for further use. Edit: Here's my code: This works but does not give me the actual physical directory location of the logs. So this is basically useless.

ManagementPath p2=new ManagementPath("IIsLogModule.Name='logging/Microsoft IIS Log File Format'");
ManagementObject log = new ManagementObject(scope, p2, objectGet);
log.Get();
logPath.Text = log["__PATH"].ToString();

解决方案

On IIS7 you could use Microsoft.Web.Administration assembly, Site class has a property named LogFile, you can get various info about log file for site, for example log file directory can be obtained with this code:

  ServerManager manager = new ServerManager();
  Site mySite = manager.Sites["SiteName"];
  Response.Write("Log file directory : " + mySite.LogFile.Directory + "\\W3svc" + mySite.Id.ToString());

I don't like very much that hardcoded part with directory prefix for site, but didn't find any other better way

这篇关于编程检索IIS中的ASP.NET应用程序日志文件位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆