Click or drag to resize
Task Scheduler Managed Class Library

TaskEventLog Class

Historical event log for a task. Only available for Windows Vista and Windows Server 2008 and later systems.
Inheritance Hierarchy
SystemObject
  Microsoft.Win32.TaskSchedulerTaskEventLog

Namespace:  Microsoft.Win32.TaskScheduler
Assembly:  Microsoft.Win32.TaskScheduler (in Microsoft.Win32.TaskScheduler.dll) Version: 2.10.1
Syntax
public sealed class TaskEventLog : IEnumerable
Request Example View Source

The TaskEventLog type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyCount
Gets the total number of events for this task.
Public propertyEnabled
Gets or sets a value indicating whether this TaskEventLog is enabled.
Public propertyEnumerateInReverse
Gets or sets a value indicating whether to enumerate in reverse when calling the default enumerator (typically with foreach statement).
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetEnumerator
Returns an enumerator that iterates through the collection.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Remarks
Many applications have the need to audit the execution of the tasks they supply. To enable this, the library provides the TaskEventLog class that allows for TaskEvent instances to be enumerated. This can be done for single tasks or the entire system. It can also be filtered by specific events or criticality.
Examples
C#
// Create a log instance for the Maint task in the root directory
TaskEventLog log = new TaskEventLog(@"\Maint",
   // Specify the event id(s) you want to enumerate
   new int[] { 141 /* TaskDeleted */, 201 /* ActionSuccess */ },
   // Specify the start date of the events to enumerate. Here, we look at the last week.
   DateTime.Now.AddDays(-7));

// Tell the enumerator to expose events 'newest first'
log.EnumerateInReverse = false;

// Enumerate the events
foreach (TaskEvent ev in log)
{
   // TaskEvents can interpret event ids into a well known, readable, enumerated type
   if (ev.StandardEventId == StandardTaskEventId.TaskDeleted)
      output.WriteLine($"  Task '{ev.TaskPath}' was deleted");

   // TaskEvent exposes a number of properties regarding the event
   else if (ev.EventId == 201)
      output.WriteLine($"  Completed action '{ev.DataValues["ActionName"]}',
         ({ev.DataValues["ResultCode"]}) at {ev.TimeCreated.Value}.");
}
See Also