I'm trying to return event log entries written by sqlserveragent. Unfortunately, I can only seem to grab all the entries at once and that takes too long. Here is the code I'm currently using:
EventLog log = new EventLog("Application", "x.x.x.x", "SQLSERVERAGENT");
var entries = log.Entries.OfType<EventLogEntry>().Where(o => o.Source == "SQLSERVERAGENT");
var c = entries.Count();
When it gets to the last line it takes so long that I don't have the patience to wait for it to finish. Is there a way for me to get a filtered view of the entries rather than having to get them all upfront and then filter them?
I found out that I need to use the EventLogQuery and EventLogReader classes in order to do this.
Still trying to figure out how to propery form the query though, so if anyone knows please do tell: EventLogQuery: How to form query string?