• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 457
  • Last Modified:

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
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

Open in new window

0
pyrokin
Asked:
pyrokin
  • 2
1 Solution
 
Wayne Taylor (webtubbs)Commented:
The Entry collection is zero based, so will always be 1 less than the Count.

Wayne
0
 
pyrokinAuthor Commented:
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.
0
 
pyrokinAuthor Commented:
It turns out that when auto overwrite is enabled the index's don't match after the overflow.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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