pyrokin
asked on
Eventlog.Entries Count does not match EventlogEntry.Index
Hello,
I am trying to figure out why is it when I receive a EventlogEntry through the EntryWritten event, the index does not match the Eventlog.Entries.Count. Can someone kindly confirm this behavior and provide a workaround? Thanks
I am trying to figure out why is it when I receive a EventlogEntry through the EntryWritten event, the index does not match the Eventlog.Entries.Count. Can someone kindly confirm this behavior and provide a workaround? Thanks
Option Explicit On
Imports System
Imports System.Diagnostics
Imports System.Threading
Class MySample
Public Shared Sub Main()
Dim myNewLog As New EventLog()
myNewLog.Log = "Security"
AddHandler myNewLog.EntryWritten, AddressOf MyOnEntryWritten
myNewLog.EnableRaisingEvents = True
Console.WriteLine("Press 'q' to quit.")
' Wait for the EntryWrittenEvent or a quit command.
While Char.ToLower(Convert.ToChar(Console.Read())) <> "q"
' Wait.
End While
End Sub ' Main
Public Shared Sub MyOnEntryWritten(ByVal source As Object, ByVal e As EntryWrittenEventArgs)
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("Entries.Count={0}", source.Entries.Count)
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("e.Entry.Index={0}", e.Entry.Index)
End Sub ' MyOnEntryWritten
End Class ' MySample
ASKER
Wayne,
Thank you for your reply. However, I should have been more detailed. I am aware the collection is zero based, but I am getting the following output from the above program:
Entries.Count=92378
e.Entry.Index=193171
Entries.Count=92378
e.Entry.Index=193172
Entries.Count=92378
e.Entry.Index=193173
Entries.Count=92378
e.Entry.Index=193174
Entries.Count=92378
e.Entry.Index=193175
Entries.Count=92378
e.Entry.Index=193176
Which is obviously a hug difference. The log in question is 29 megs is size.
Thank you for your reply. However, I should have been more detailed. I am aware the collection is zero based, but I am getting the following output from the above program:
Entries.Count=92378
e.Entry.Index=193171
Entries.Count=92378
e.Entry.Index=193172
Entries.Count=92378
e.Entry.Index=193173
Entries.Count=92378
e.Entry.Index=193174
Entries.Count=92378
e.Entry.Index=193175
Entries.Count=92378
e.Entry.Index=193176
Which is obviously a hug difference. The log in question is 29 megs is size.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Wayne