Event Log Filter

jagoh87

Member
Joined
Nov 21, 2006
Messages
8
Programming Experience
Beginner
I have the following to read the "System" Event Log.

VB.NET:
        SetupEventsListView()
        Dim elEvent As New System.Diagnostics.EventLog("System")
        Dim elEventEntry As System.Diagnostics.EventLogEntry
        For Each elEventEntry In elEvent.Entries
            Dim li As New ListViewItem()
            With li
                .Text = elEventEntry.EntryType.ToString
                .SubItems.Add(elEventEntry.TimeGenerated.ToString)
                .SubItems.Add(elEventEntry.Source.ToString)
                .SubItems.Add(elEventEntry.Category.ToString)
                .SubItems.Add(elEventEntry.EventID.ToString)
                If elEventEntry.UserName Is Nothing Then
                    .SubItems.Add("N/A")
                Else
                    .SubItems.Add(elEventEntry.UserName.ToString)
                End If

                .SubItems.Add(elEventEntry.MachineName.ToString)
                .SubItems.Add(elEventEntry.Message.ToString)
            End With
            lvwEvents.Items.Add(li)
            li = Nothing
            lvwEvents.Refresh()
        Next

What i want to be able to do is for the app to only read the "Errors" in the event log.
Does anyone know of a way i can do this?

Thanks for the help
 

jagoh87

Member
Joined
Nov 21, 2006
Messages
8
Programming Experience
Beginner
sorry this part i simply added
VB.NET:
elEventEntry.EntryType = EventLogEntryType.Error

The part im struggling with is the following:

VB.NET:
Public Class EventAlert
    Private Shared signal As AutoResetEvent

    Public Shared Sub main()
        Dim EvLog As New EventLog
        EvLog.Log = "System"
        AddHandler EvLog.EntryWritten, AddressOf MyOnEntryWritten
        EvLog.EnableRaisingEvents = True
        signal = New AutoResetEvent(False)
        signal.WaitOne()

    End Sub
    Public Shared Sub MyOnEntryWritten(ByVal [source] As Object, ByVal e As EntryWrittenEventArgs)
        EventViewerMonitor.email()
        EventViewerMonitor.btnRead.PerformClick()
        signal.Set()
    End Sub

   
End Class
 

shawne

Well-known member
Joined
Feb 22, 2006
Messages
103
Location
Pennsylvania
Programming Experience
10+
"filter" eventlog?

Is there a way to "filter" events? For example, I want all Application events from 8/28/08 to 8/29/08 ...
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,583
Location
Norway
Programming Experience
10+
Just compare TimeGenerated of each EventLogEntry with your dates.
 

shawne

Well-known member
Joined
Feb 22, 2006
Messages
103
Location
Pennsylvania
Programming Experience
10+
Ya, thats what i ended up doing ... I was hoping to avoid having to loop through each entry and compare it. I was looking for a solution like what you can do with the "Filter" option in eventviewer. I think the problem I had was there were tens of thousands events on the box I was pulling from, so populating the listview I was using took forever. I thought about dumping the contents into an XML file, then binding it to a datagridview for a faster immediate response, but it would still take time to update the XML file ...... perhaps i need to write a service which would update it it behind the scenes. .. grrr ... this app. is creeping all over the place.. Thanks for the input!
 
Top Bottom