[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

Best method for reading event logs.

Hi,

I'm writing an app to collate the outcome of Backup Exec backups. This basically involves using the System.Diagnostics.EventLog class to read through all the entries on a machine, that have a source of "Backup Exec", and then pulling those entries out into an array.

The problem I have, is that some of the machines have in excess of 50,000 events in their application log (that raises housekeeping questions - but we'll ignore those for now), which means my app takes ages to trawl through them all.

What makes this worse is that the events i'm interested in are generally the newest, and the iteration through the event log starts with the oldest, so I nomally have 49000+ iterations that don't need to occur.

Is there anyway I can reverse the direction of the iteration through eventlog.entries?  This means I would be able to break out of the loop as soon as I had found the event i'm after.

Cheers

M
0
lambch0p
Asked:
lambch0p
1 Solution
 
sumixCommented:

 Property Entries of an EventLog is an indexed collection, so you can access its entries by index:
 
EventLog lg = new EventLog("Application");
MessageBox.Show(lg.Entries[lg.Entries.Count-1].Source);
0
 
lambch0pAuthor Commented:
That's what I was after.


Cheers

M
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now