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.12.0
Syntax
C#
public sealed class TaskEventLog : IEnumerable
Request Example View Source

The TaskEventLog type exposes the following members.

Constructors
 NameDescription
Public methodTaskEventLog(String) Initializes a new instance of the TaskEventLog class.
Public methodTaskEventLog(String, String, String, String, String) Initializes a new instance of the TaskEventLog class.
Public methodTaskEventLog(DateTime, String, String, String, String, String) Initializes a new instance of the TaskEventLog class that looks at all task events from a specified time.
Public methodTaskEventLog(String, Int32, NullableDateTime, String, String, String, String) Initializes a new instance of the TaskEventLog class.
Public methodTaskEventLog(String, Int32, Int32, NullableDateTime, String, String, String, String) Initializes a new instance of the TaskEventLog class.
Top
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 methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Protected methodFinalizeAllows 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 methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
Public methodToStringReturns 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.
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}.");
}
See Also