Example #1
0
        static void Main(string[] args)
        {
            // bail out if the user isn't running Windows 10
            if (Environment.OSVersion.Version.Major < 10)
            {
                Console.WriteLine();
                Console.WriteLine("Coloma requires Windows 10");
                Console.WriteLine();
                Console.WriteLine("Hit any key to exit");
                Console.ReadKey(true);

                return;
            }

            // Inform the user we're running
            Console.WriteLine();
            Console.WriteLine("Coloma is gathering log entries for your machine.");
            Console.WriteLine();

            // create the file on the network share, unless it's unavailable, then use the desktop
            string       filename = Assembly.GetExecutingAssembly().GetName().Version.ToString() + "_" + Environment.MachineName + "_" + Environment.UserName + "_" + Environment.TickCount.ToString() + ".tsv";
            string       filepath = @"\\iefs\users\mattgr\Coloma" + "\\Coloma" + "_" + filename;
            StreamWriter sw;

            try
            {
                sw = new StreamWriter(filepath, false, System.Text.Encoding.UTF8);
            }
            catch (Exception)
            {
                filepath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Coloma" + "_" + filename;
                sw       = new StreamWriter(filepath, false, System.Text.Encoding.UTF8);

                Console.WriteLine("Coloma could not access the network share and will write the .tsv to your desktop.");
            }

            // just get logs since last time OR since 4/1/2016
            DateTime dt = new DateTime(2016, 4, 1, 0, 0, 0, 0, DateTimeKind.Local);

            GetLastColomaDate(ref dt);

            // Tell the user what we're doing
            Console.WriteLine("Any error, warning, or KB install written after " + dt.ToShortDateString());
            Console.WriteLine("From the following logs: System, Security, Hardware Events, Setup, and Application");
            Console.WriteLine("Data will be saved to " + filepath);

            if (DeviceId.Contains("UNKNOWN"))
            {
                Console.WriteLine("WARNING: Coloma could not automatically detect your DeviceID.");
            }

            Console.WriteLine();

            Console.Write("KB Articles for revision install history... ");
            // TH2 revisions
            List <KBRevision> kbrlist = new List <KBRevision>
            {
                new KBRevision(10586, 420, "KB3163018"),
                new KBRevision(10586, 318, "KB3156421"),
                new KBRevision(10586, 218, "KB3147458"),
                new KBRevision(10586, 164, "KB3140768"),
                new KBRevision(10586, 122, "KB3140743"),
                new KBRevision(10586, 104, "KB3135173"),
                new KBRevision(10586, 71, "KB3124262"),
                new KBRevision(10586, 63, "KB3124263"),
                new KBRevision(10586, 36, "KB3124200"),
                new KBRevision(10586, 29, "KB3116900"),
                new KBRevision(10586, 17, "KB3116908"),
                new KBRevision(10586, 14, "KB3120677"),
                new KBRevision(10586, 11, "KB3118754")
            };

            Console.WriteLine("done");

            List <ColomaEvent> eventlist = new List <ColomaEvent>();

            // Setup logs are different than other logs
            Console.Write("Setup... ");
            bool setuplog = AddSetupLogToList(kbrlist, eventlist, dt);

            Console.WriteLine("done");

            // Go through the 'standard' logs
            string[] Logs = { "System", "HardwareEvents", "Application", "Security" };
            foreach (string log in Logs)
            {
                EventLog eventlog = new EventLog(log, ".");
                Console.Write(log + "... ");
                AddStandardLogToList(eventlog, eventlist, dt);
                eventlog.Close();
                Console.WriteLine("done");
            }

            // gets all the events in order, and uses info from the setup log to ensure the correct revision
            // if the setuplog had no entries, then use the current build and revision
            Console.Write("Sort and fixup... ");
            SortandFix(eventlist, setuplog);
            Console.WriteLine("done");

            Console.Write("Writing file");
            int i = 0;

            sw.WriteLine(ColomaEvent.Header());
            foreach (ColomaEvent evt in eventlist)
            {
                i++;
                sw.WriteLine(evt.ToString());
                if (i % 10 == 0)
                {
                    Console.Write(".");
                }
            }
            Console.WriteLine(" done");
            sw.Close();

            Console.WriteLine();
            Console.WriteLine("Done, thank you. Hit any key to exit");
            Console.ReadKey(true);
        }