Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically retrieving IIS log file location in an ASP.NET application

Tags:

asp.net

iis

wmi

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();
like image 712
Slethron Avatar asked Feb 27 '12 09:02

Slethron


People also ask

Where is IIS LogFiles located?

IIS log files are stored by default in the %SystemDrive%\inetpub\logs\LogFiles folder of your IIS server.

What is stored in IIS logs?

IIS logs are meant to record data from Internet Information Services, web pages, and apps. While IIS itself contributes to the scalability and flexibility of web resources, the log files contain specific statistics about the websites, user data, site visits, IPs, and queries.


1 Answers

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

like image 160
Antonio Bakula Avatar answered Sep 30 '22 15:09

Antonio Bakula