To read from the end, just use a for loop and Entries.Count. Be careful
about reading all the entries in first It can be many megabytes of data. I
recommend reading them in one at a time and stopping when you get past 1 day
old, like this:
EventLog myLog = new EventLog("Syste m");
for(int x = myLog.Entries.C ount - 1; x >= 0; x--)
{
EventLogEntry entry = myLog.Entries[x];
if (entry.TimeGene rated < DateTime.Now.Ad dDays(-1))
{
break;
}
// save the item
this.MySaveToSq lMethod(entry.T imeGenerated, entry.Message);
}
HTH
Dale Preston
MCAD, MCDBA, MCSE
<kr*******@gmai l.com> wrote in message
news:11******** **************@ l41g2000cwc.goo glegroups.com.. .
Hi,
I'm trying to write small program that reads events from computer
and stores them in SQL database.
But I don't know hove to read logs for let's say last 24 hours,
one solution is to read all events in event log and then check time.
foreach(EventLo gEntry Entry in logSystem.Entri es) {
//
// check time
//
}
And if a have 100k entries, this can take time.
Can I read logs from last to first?
Mihalic Krunoslav