-1

I am trying to create a program that will automatically keep track of the windows task scheduler and will notify me via email if a ny of the scheduled task fails to launch. I am C# as the programming language. I've checked various references but haven't been able to achieve this. Can anyone please provide me any reference or suggestion as to how I can access the log and check if any task launch has failed?

Here's my code:

        EventLog demoLog = new EventLog();
        demoLog.Source="Microsoft-Windows-TaskScheduler/Operational";
        try
        {
            EventLogEntryCollection entries = demoLog.Entries;
            foreach (EventLogEntry entry in entries)
            {
                Console.WriteLine("Level: {0}", entry.EntryType);
                Console.WriteLine("Event id: {0}", entry.InstanceId);
                Console.WriteLine("Message: {0}", entry.Message);
                Console.WriteLine("Source: {0}", entry.Source);
                Console.WriteLine("Date: {0}", entry.TimeGenerated);
                Console.WriteLine("--------------------------------");
            }
        }
        catch(Exception e)
        {
            Console.Write(e.Message);
        }

1 Answers1

0

Check this link.

They use there an EventlogReader to get the information. Maybe it help. I managed to read the events from my computer using it.

neer
  • 4,031
  • 6
  • 20
  • 34
Gilad Green
  • 36,708
  • 7
  • 61
  • 95
  • It works for me as well @Gilad Green but can you help me in finding the time an event occurred? – Rajdeep Nandi Jun 20 '16 at 11:54
  • @Rajdeep Nandi - It has a property TimeCreated that by the MSDN documentation is the time where the log record was created (makes sense :) ). [Here is the documentation](https://msdn.microsoft.com/en-us/library/system.diagnostics.eventing.reader.eventrecord(v=vs.110).aspx) – Gilad Green Jun 20 '16 at 12:08
  • Yeah now I've found out the way...@Gilad Green – Rajdeep Nandi Jun 20 '16 at 12:28