Create and Delete Custom Event Logs
Create the Custom Log
Use the CreateEventSource method to create your own custom event handler.
Before you create the event log, use the SourceExists method to verify that the source you are using does not already exist, and then call CreateEventSource.
If you try to create an event log that already exists, a System.ArgumentException error is thrown.
The following code example demonstrates how to create a custom log:
' Check if the log already exist
If Not EventLog.SourceExists("MyOldSource", System.Environment.MachineName) Then
' Creating a new log
EventLog.CreateEventSource("MyOldSource", "MyNewLog", System.Environment.MachineName)
Console.WriteLine("New event log created successfully.")
End If
You Can Write Event logs on Button Click Event
--------EXAMPLE-----------------
Private Sub btnWriteEntry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWriteEntry.Click
'Write an entry to the Application Log. Notice the use of "DemoEventLog", this is the source that will be used
'for this application and is used to state what application/service the log refers too.
Dim elLog As New System.Diagnostics.EventLog("Application", Environment.MachineName, "DemoEventLog")
elLog.WriteEntry("This is a information message", EventLogEntryType.Information)
elLog.WriteEntry("This is a warning message", EventLogEntryType.Warning)
elLog.WriteEntry("This is a Error message", EventLogEntryType.Error)
elLog.WriteEntry("This is a Success Audit message", EventLogEntryType.SuccessAudit)
elLog.WriteEntry("This is a Failed Audit message", EventLogEntryType.FailureAudit)
elLog.Dispose()
End Sub
It'sVery informative blog and useful article thank you for sharing with us , keep posting learn
ReplyDeletemore about Dot net
.NET Online Training Hyderabad
Thanks a lot for sharing such a good source with all, i appreciate your efforts taken for the same. I found this worth sharing and must share this with all.
ReplyDeleteDot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery