Getting the Contents of an Event Log
Event log entries can be obtained individually for evaluation by your program. The EventLog.Entries property returns an array of EventLogEntry objects. You can iterate through the array to look for specific kinds of entries or just print all entries, as the code in Listing 20.1 demonstrates.
Listing 20.1. Iterating over EventLogEntry objects
1: Private Sub DisplayEntries(ByVal LogName As String) 2: 3: If (Not EventLog.Exists(LogName)) Then Exit Sub 4: 5: TextBox1.Clear() 6: Dim Log As New EventLog(LogName) 7: Try 8: 9: Dim Entry As EventLogEntry 10: For Each Entry In Log.Entries 11: TextBox1.Text = TextBox1.Text & Entry.Message & _ 12: vbCrLf 13: Next 14: 15: Finally 16: Log = Nothing 17: End Try 18: 19: ... |
Get Visual Basic® .NET Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.