Prizes & Awards
My Profile
Active Members
TodayLast 7 Days
more...
|
Resources » Code Snippets » Application windows, menus & toolbars »
Writing the event log VB.NET
|
This code shows how to write event log in VB.NET
Private Sub cmdWriteEntry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles btnWriteEntry.Click
Try If IsNumeric(txtEventID.Text) Then
' When writing to an event log you need to pass the machine name where ' the log resides. Here the MachineName Property of the Environment class ' is used to determine the name of the local machine. Assuming you have ' the appropriate permissions it is also easy to write to event logs on ' other machines.
' The first entry is the name of the log you want to write to. The second ' parameter is the machine name. In this case it is the local machine name. ' The third parameter is the source of the event. Commonly this is set equal ' to the name of the application that is writing the event.
Dim ev As New EventLog("Application", System.Environment.MachineName, _ "How-To Use the Event Log")
' The first argument to WriteEntry is the text of the message. The second ' argument is the type of entry you want to create (Warning, Information, etc.) ' The third is the eventID of the event. The user could use this to look up ' further information in a help file.
ev.WriteEntry(txtEntry.Text, entryType, CInt(txtEventID.Text))
ev.Close()
MessageBox.Show("Entry written to the event log", _ "frmWrite", _ MessageBoxButtons.OK, _ MessageBoxIcon.Information) Else ' The EventID was not numeric MessageBox.Show("Value entered into EventID textbox must be numeric", _ "Event ID Entry Error", _ MessageBoxButtons.OK, _ MessageBoxIcon.Exclamation) End If
Catch secEx As SecurityException MessageBox.Show("Error writing to the event log: this may be due to a lack of appropriate permissions." & vbCrLf & secEx.Message, _ "Lack of Permissions", _ MessageBoxButtons.OK, _ MessageBoxIcon.Error) Catch ex As Exception MessageBox.Show("Error accessing logs on the local machine." & vbCrLf & ex.Message, _ "Error accessing logs.", _ MessageBoxButtons.OK, _ MessageBoxIcon.Error) End Try
End Sub
|
Responses
|
No responses found. Be the first to respond and make money from revenue sharing program.
|
|