TaskEventLog Class

Historical event log for a task. Only available for Windows Vista and Windows Server 2008 and later systems.

Definition

Namespace: Microsoft.Win32.TaskScheduler
Assembly: Microsoft.Win32.TaskScheduler (in Microsoft.Win32.TaskScheduler.dll) Version: 2.11.0
public sealed class TaskEventLog : IEnumerable
Inheritance
Object    TaskEventLog
Implements
IEnumerable

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.

Example

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}.");
}

Constructors

TaskEventLog(String) Initializes a new instance of the TaskEventLog class.
TaskEventLog(String, String, String, String, String) Initializes a new instance of the TaskEventLog class.
TaskEventLog(DateTime, String, String, String, String, String) Initializes a new instance of the TaskEventLog class that looks at all task events from a specified time.
TaskEventLog(String, Int32, NullableDateTime, String, String, String, String) Initializes a new instance of the TaskEventLog class.
TaskEventLog(String, Int32, Int32, NullableDateTime, String, String, String, String) Initializes a new instance of the TaskEventLog class.

Properties

Count Gets the total number of events for this task.
Enabled Gets or sets a value indicating whether this TaskEventLog is enabled.
EnumerateInReverse Gets or sets a value indicating whether to enumerate in reverse when calling the default enumerator (typically with foreach statement).

Methods

EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
GetEnumerator Returns an enumerator that iterates through the collection.
GetHashCodeServes as the default hash function.
(Inherited from Object)
GetTypeGets the Type of the current instance.
(Inherited from Object)
MemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
ToStringReturns a string that represents the current object.
(Inherited from Object)

See Also