C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Application windows, menus & toolbars »

Writing the event log VB.NET


Posted Date: 08 Dec 2008    Resource Type: Code Snippets    Category: Application windows, menus & toolbars
Author: SravyaMember Level: Gold    
Rating: 1 out of 5Points: 10



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.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Writing the event log VB.NET  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Reading the event logs VB.NET
Previous Resource: selecting data table rows
Return to Discussion Resource Index
Post New Resource
Category: Application windows, menus & toolbars


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use