The following are the codes I use to retrieve the EventLogEntry based on the source instead of log.

Is there a much simpler way

EventLog cLog=new EventLog("Application");

foreach (EventLogEntry entry in cLog.Entries)


if(entry.Source=="C# application")



Re: .NET Base Class Library To retrieve EventLogEntry based on the source


Not really. Internally the enumerator uses the underlying Win32 API to retrieve the log entries. The API does not allow for filtering. You could however wrap the above code in a simple function to give the illusion of filtering. Clients can then pass the source and log as input and get back only the events that match. You need to be a little careful though as there can be a lot of entries. The class itself pulls the data back when requested rather than caching the entries internally. You should follow a similar approach.

Michael Taylor - 5/7/07