Getting log file

May 22, 2009 at 11:23 AM

Perhaps you could incorperate some code I wrote to collect log files into a tempory store then automatticly load them by site comment in IIS:-  Save the user some time esspecially if they want to look at the whole picture.  I havn't seen any tools that do this yet but I think something like that would look cool in yours.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

using System.DirectoryServices;

 

namespace MergeLogs

{

    class Program

    {

        static void Main(string[] args)

        {

            if (args.Length == 1)

            {

                //string logPath = @"C:\inetpub\logs\LogFiles"; 

                string logPath = args[0];

 

                DirectoryEntry w3svc = new DirectoryEntry(string.Format("IIS://{0}/w3svc", "127.0.0.1"));

                var siteInformations =

                    from DirectoryEntry site in w3svc.Children

                    where site.Properties["ServerComment"] != null && site.Properties["ServerComment"].Value != null

                    select new { Name = site.Properties["ServerComment"].Value.ToString(), ID = site.Name };

 

                foreach (var site in siteInformations)

                {

                    if (Directory.Exists(Path.Combine(logPath, "W3SVC" + site.ID)))

                    {

                        File.Delete(site.Name + ".log");

                        IEnumerable<string> files =

                            from fi in new DirectoryInfo(Path.Combine(logPath, "W3SVC" + site.ID)).GetFiles("*.log")

                            orderby fi.LastWriteTime ascending

                            select fi.FullName;

                        double x = 1;

                        double length = files.Count();

                        if (length > 0)

                        {

                            Console.WriteLine("Creating log for " + site.Name);

                            foreach (string fileName in files)

                            {

                                Console.SetCursorPosition(0, Console.CursorTop);

                                Console.Write("9876543210".Substring(0, (int)(x++ / length * 10)));

                                try

                                {

                                    File.AppendAllText(site.Name + ".log", File.ReadAllText(fileName));

                                }

                                catch { }

                            }

                            Console.WriteLine();

                        }

                    }

                    else

                    {

                        Console.WriteLine("Skipping " + site.Name);

                    }

                }

 

                Console.WriteLine("Completed.  Press any key to continue");

                Console.ReadKey();

            }

            else

            {

                Console.WriteLine("You need to execute this inside a blank folder with and provide the IIS log base path as a string.\r\nThe programe will then merge the log files into webSiteName.log by last modifed time\r\n\r\nPress any key to exit");

                Console.ReadKey();

            }

        }

    }

}


Coordinator
May 25, 2009 at 7:25 AM

awesome, thanks for your sharing. I have a plan for this.

May 26, 2009 at 10:33 AM

Keep with it I'm really excited about this project