0

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.

EventLogReader reader = new 
EventLogReader(eventLogQuery);
                reader.Seek(SeekOrigin.Begin, filter.PageStart);

eventLogs.TotalLogs = **totalRowsAffected**;                    
EventRecord eventInstance = reader.ReadEvent();

int i = filter.PageSize;
while (eventInstance != null && i-- > 0)
{
 try
 {
  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()
  });
 }catch{}
eventInstance = reader.ReadEvent();
}
}
return eventLogs;
James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

0

I think you can use the following to get the total number of entries in an event log.

var myEventLog = new EventLog();
myEventLog.Log = myLogName;
entries = myEventLog.Entries;
var total = entries.Count;
Priyan Perera
  • 560
  • 1
  • 7
  • 20
  • EventLogReader readerForCount = new EventLogReader(eventLogQuery); readerForCount.Seek(SeekOrigin.Begin, 0); EventRecord eventInstanceCounter = readerForCount.ReadEvent(); How do we get the count of records read by eventReader without using loop? – Shanmuga Sundaram Feb 19 '18 at 08:05