FroggEye, thank you for the tip.
There is no sample in documentation how to delete a log item so here is the snippet of the shceduled task for the others:
public string Execute(TaskInfo ti)
{
// Create new instance of event log provider
EventLogProvider eventLog = new EventLogProvider();
string[] splitUsers = ti.TaskData.Split(';');
foreach (string user in splitUsers)
{
// Get events matching the where condition
string where = "UserName = '" + user + "'";
DataSet events = eventLog.GetAllEvents(where, null);
if (!DataHelper.DataSourceIsEmpty(events))
{
int cnt = 0;
// Loop through the individual items
foreach (DataRow eventDr in events.Tables[0].Rows)
{
// Create the object from DataRow
EventLogInfo deleteEvent = new EventLogInfo(eventDr);
//Delete log
deleteEvent.Destroy();
eventLog.SetEventLogInfo(deleteEvent);
cnt++;
}
string detail = cnt.ToString() + " events of user '" + user + "' deleted from Event Log.";
// Logs the execution of the task in the event log.
EventLogProvider.LogInformation("DeleteUsers", "Execute", detail);
}
}
return null;
}
Add user names delimited by ';' to Task Data property of your Scheduled Task.
Vlado