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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 454
  • 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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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