How to write Data in Eventlog

Posted by Goldytech under Others category on | Views : 2558
It makes lot of sense to write data into Windows Event Log for the applications that dosen't have any user intervention like Windows Services.
This code snippet teaches you the same.

Imports System.Diagnostics
Private Sub WriteInEventLog(ByVal Text As String, ByVal Type As EventLogEntryType)
If Not EventLog.SourceExists("YourEventSourceName") Then 'check first whether event source exists if not then create it
EventLog.CreateEventSource("YourEventSourceName", "YourEventLogName")
End If
Dim EvLog As New EventLog
EvLog.Source = "YourEventSourceName"
EvLog.WriteEntry(Text, Type)
End Sub

Comments or Responses

Login to post response