
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Searching Event Log Entries
|
459
Discussion
Other searchable criteria can be added to this class by following the same coding pat-
tern for each search method. For instance, the following example shows how to add
a search method to find all entries that contain a particular username:
public static EventLogEntry[] FindUserName(IEnumerable logEntries,
string userNameQuery)
{
ArrayList entries = new ArrayList( );
foreach (EventLogEntry logEntry in logEntries)
{
if (logEntry.UserName == userNameQuery)
{
entries.Add(logEntry);
}
}
EventLogEntry[] entriesArray = new EventLogEntry[entries.Count];
entries.CopyTo(entriesArray);
return (entriesArray);
}
entries.Add(logEntry);
}
}
EventLogEntry[] entriesArray = new EventLogEntry[entries.Count];
entries.CopyTo(entriesArray);
return (entriesArray);
}
public static EventLogEntry[] FindTimeGeneratedAtOrAfter(
IEnumerable logEntries, DateTime timeGeneratedQuery)
{
ArrayList entries = new ArrayList( );
foreach (EventLogEntry logEntry in logEntries)
{
if (logEntry.TimeGenerated >= timeGeneratedQuery)
{
entries.Add(logEntry);
}
}
EventLogEntry[] entriesArray = new EventLogEntry[entries.Count];
entries.CopyTo(entriesArray);
return (entriesArray);
}
}
Example 8-4. EventSearchLog class (continued)