I am trying to read the contents of IIS logfiles using C#, but I do not know how to find where they are. The physical location on my PC is C:\inetpub\logs\LogFiles\W3SVC1.
In my software I am using:
string serverName =
"localhost";
DirectoryEntry W3SVC =
new
DirectoryEntry("IIS://" + serverName +
"/logs/logfiles/w3svc/1");
foreach (DirectoryEntry d
in W3SVC.Children)
{
MessageBox.Show(d.Name);
}
But it says the path does not exist. I am also not sure that the foreach will bring back each file within the directory anyway. I think it will bring back each child directory, which is not what I want.
Can anyone point me in the right direction please.
grnr_rchrd
5 Posts
IIS Logfiles Location
Aug 13, 2008 07:05 PM|LINK
I am trying to read the contents of IIS logfiles using C#, but I do not know how to find where they are. The physical location on my PC is C:\inetpub\logs\LogFiles\W3SVC1.
In my software I am using:
string serverName = "localhost"; DirectoryEntry W3SVC = new DirectoryEntry("IIS://" + serverName + "/logs/logfiles/w3svc/1"); foreach (DirectoryEntry d in W3SVC.Children){
MessageBox.Show(d.Name);}
But it says the path does not exist. I am also not sure that the foreach will bring back each file within the directory anyway. I think it will bring back each child directory, which is not what I want.
Can anyone point me in the right direction please.
IIS7 C#
jeff@zina.co...
3379 Posts
MVP
Moderator
Re: IIS Logfiles Location
Aug 14, 2008 02:35 PM|LINK
Look in that folder and see if they really are there. Check permissions on the file/folder.
Jeff
dac3636
6 Posts
Re: IIS Logfiles Location
Aug 14, 2008 08:06 PM|LINK
If all your trying to do is get the logfile names under that directory, try this.
DirectoryInfo iisDir = new DirectoryInfo(@"C:\inetpub\logs\LogFiles\W3SVC1");
FileInfo[] myfiles;myfiles = iisDir.GetFiles();
foreach (FileInfo logfile in myfiles){
Console.WriteLine(logfile.Name.ToString());}
Like the other reply said, make sure to check the security on the directory.
steve schofi...
5681 Posts
MVP
Moderator
Re: IIS Logfiles Location
Aug 15, 2008 05:14 AM|LINK
You are using the IIS provider, do you have the legacy tools installed?
Steve Schofield
Windows Server MVP - IIS
http://iislogs.com/steveschofield
http://www.IISLogs.com
Log archival solution
Install, Configure, Forget