Hi Greg,

I don't have an IIS Server at work but this guy seems to be doing something
similar and he claims that it works. It seems like he's looking higher up
the tree or something (this might be an IIS6 vs 7 thing)

foreach (DirectoryEntry Site in new DirectoryEntry("IIS://" +
System.Environment.MachineName + "/w3svc").Children)
{
  if (String.Compare(Site.SchemaClassName, "IIsWebServer",
StringComparison.OrdinalIgnoreCase) == 0)
  {
    Console.WriteLine(Site.Properties["ServerComment"].Value.ToString());
    Console.WriteLine(Site.Properties["LogFileDirectory"].Value.ToString());
  }
}


http://www.eggheadcafe.com/software/aspnet/33370610/how-to-determine-the-location-of-log-files-using-managed-code.aspx


On Fri, Apr 8, 2011 at 2:02 PM, Greg Keogh <[email protected]> wrote:

> Folks, I was hoping to get the names of the folder where log files from my
> web sites are stored. Thanks to some web hints I wrote the following crude
> sanity check code to dump the properties of all sites:
>
>
>
> private void button1_Click(object sender, EventArgs e)
>
> {
>
>     listBox1.Items.Clear();
>
>     for (int webseq = 1; ; ++webseq)
>
>     {
>
>         try
>
>         {
>
>             StringBuilder sb = new StringBuilder();
>
>             string uri = string.Format("IIS://feeder/W3SVC/{0}/ROOT",
> webseq);
>
>             DirectoryEntry parent = new DirectoryEntry(uri);
>
>             listBox1.Items.Add("=============" + uri + "=============");
>
>             foreach (PropertyValueCollection pvc in parent.Properties)
>
>             {
>
>                 listBox1.Items.Add(string.Format("• {0}\n",
> pvc.PropertyName));
>
>                 for (int i = 0; i < pvc.Count; i++)
>
>                 {
>
>                     object val = pvc[i];
>
>                     listBox1.Items.Add(string.Format("--- {0}\n", val));
>
>                 }
>
>             }
>
>         }
>
>         catch
>
>         {
>
>             break;
>
>         }
>
>     }
>
> }
>
>
>
> This certainly dumps lots of interesting properties such as Pool name,
> default docs, user name, flags, custom headers, etc. Sadly it doesn’t give
> the one piece of information I want ... the location of the log files.
>
>
>
> Does anyone know where I can get that information?
>
>
>
> Cheers,
>
> Greg
>

Reply via email to