How to find total rows affected when using EventLogReader

Feb 22 2018 12:48 AM
I'm trying to read eventlogs from a server which has about 100 000 records using class EventLogReader(eventLogQuery).
 
I'm using pagination and each page will show only 25 records in my screen. So, I will be reading 25 records out of total records for the first page and next 25 records for the second page and so on.
 
My question is how to get the total records count for the below snippet like total rows affected because of that eventLogQuery applied on full set of events?
  1. EventLogReader reader = new EventLogReader(eventLogQuery);  
  2. reader.Seek(SeekOrigin.Begin, filter.PageStart);  
  3. eventLogs.TotalLogs = **totalRowsAffected**;  
  4. EventRecord eventInstance = reader.ReadEvent();  
  5. int i = filter.PageSize;  
  6. while (eventInstance != null && i-- > 0)  
  7. {  
  8. try  
  9. {  
  10. eventLogs.Entries.Add(new EventLogData { Type = eventInstance.LevelDisplayName, Source = eventInstance.ProviderName, Time = eventInstance.TimeCreated, Category = eventInstance.TaskDisplayName, EventId = eventInstance.Id, User = eventInstance.UserId != null ? eventInstance.UserId.Value : "", Computer = eventInstance.MachineName, Message = eventInstance.FormatDescription(), FullXml = eventInstance.ToXml() });  
  11. }  
  12. catch{}  
  13. eventInstance = reader.ReadEvent();  
  14. }  
  15. }  
  16. return eventLogs;

Answers (1)