-
Dec 13th, 2012, 04:00 PM
#1
Thread Starter
Member
View specific Event Log entry
Hi.
I’m working on getting certain Event Log Entries from the Event Log.
What I’d like to achieve is:
A user can select which Event Log Entry Type he wants to view. E.g: “Error”, “Warning”, “Information” etc…
He should also be able to choose from which category he wants the logs. E.g: “System”, “Application” etc…
After he has selected, only the Last 10 entries of that (selected) type should be saved to a text file.
Help is really appreciated. If you want I can upload the whole Project.
I have really no idea how to achieve this, but I did get the following code from a website which gets the event log entries and outputs to a rich textbox, but It doesn’t achieve what I want to.
Code:
Public Class ReadForm
' Stores the name of the log that the user wants to view.
Private logType As String = ""
Private Sub cmdViewLogEntries_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewLogEntries.Click
Try
Const EntriesToDisplay As Integer = 10
' In this case the EventLog constructor is passed a string variable for the log name.
' This is because the user of the application can choose which log they wish to view
' from the listbox on the form.
Dim ev As New EventLog(logType, System.Environment.MachineName, "Event Log Sample")
rchEventLogOutput.Text = "Event log entries (maximum of 10), newest to oldest." & vbCrLf & vbCrLf
Dim lastLogToShow As Integer = ev.Entries.Count - EntriesToDisplay
If lastLogToShow < 0 Then
lastLogToShow = 0
End If
' Display the last 10 records in the chosen log.
For index As Integer = ev.Entries.Count - 1 To lastLogToShow Step -1
Dim CurrentEntry As EventLogEntry = ev.Entries(index)
'rchEventLogOutput.Text &= "Event ID : " & CurrentEntry.InstanceId & vbCrLf
rchEventLogOutput.Text &= "Event ID : " & CurrentEntry.EntryType.Error & vbCrLf
rchEventLogOutput.Text &= "Entry Type : " & EventLogEntryType.Error.ToString() & vbCrLf
rchEventLogOutput.Text &= "Message : " & CurrentEntry.Message & vbCrLf & vbCrLf
Next
Catch secEx As System.Security.SecurityException
MsgBox("Security exception in reading the event log.", MsgBoxStyle.OKOnly, Me.Text & " Error")
Catch ex As Exception
MsgBox("Error accessing logs on the local machine.", MsgBoxStyle.OKOnly, Me.Text & " Error")
End Try
End Sub
Private Sub lstEntryType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstEntryType.SelectedIndexChanged
' Store the log that the user selected in the ListBox
logType = CType(lstEntryType.Items(lstEntryType.SelectedIndex()), String)
End Sub
Private Sub ReadForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
For Each currentLog As EventLog In EventLog.GetEventLogs()
lstEntryType.Items.Add(currentLog.LogDisplayName)
Next
lstEntryType.SelectedIndex = 0
Catch secEx As System.Security.SecurityException
MsgBox("Security exception in reading the event log.", MsgBoxStyle.OKOnly, Me.Text & " Error")
Catch ex As Exception
MsgBox("Error accessing logs on the local machine.", MsgBoxStyle.OKOnly, Me.Text & " Error")
End Try
End Sub
End Class
-
Dec 13th, 2012, 06:32 PM
#2
Re: View specific Event Log entry
Specifically what does the code you got doesn't do that you would like it to do ?
-
Dec 15th, 2012, 07:11 AM
#3
Thread Starter
Member
Re: View specific Event Log entry
Thanks for replying back.
The code I got doesn't get accurate results.
When I edit the code to give me Event Log Entries for "Error", it doesn't give me what I see in the Event Viewer.
If It helps here's the link to the sample project.
PS: I do not own it, I found it on the Internet.
-
Dec 19th, 2012, 11:26 AM
#4
Thread Starter
Member
Re: View specific Event Log entry
Still waiting desperately for a reply...
Last edited by TheThinker; Dec 22nd, 2012 at 08:53 AM.
-
Jan 2nd, 2013, 10:00 AM
#5
Thread Starter
Member
Re: View specific Event Log entry
Problem solved thanks to a reply in another thread...
Thanks anyways..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|