J
John Smith
I have created a windows service that logs errors to the EventLog. I want
the logs to go to an EventLog I have created. However, I am finding that
the event is not logging to the created EventLog instead it is logging to
Application log. What could be the problem?
========================================================================
SYSTEM DETAILS:
========================================================================
Operating System: Windows 2000 Professional SP4
..NET Version: 1.1.4322
========================================================================
CODE:
========================================================================
Public Class MyClass
Private _EventSourceName As String = "MySource"
Private _EventLogName As String = "MyLog"
'**********************************************************************
'*** DESCRIPTION: Adds entries to the Application Log.
'**********************************************************************
Private Sub Add( _
ByVal DisplayMessage As String, _
ByVal objEventLogEntryType As EventLogEntryType, _
ByVal EventID As Integer, _
ByVal Category As Short _
)
'*** Create new event log ***
Dim oEventLog As New EventLog
'*** If the the Event Log does not exist, then create one.
If Not oEventLog.SourceExists(_EventSourceName) Then
'*** Create Log ***
oEventLog.CreateEventSource(_EventSourceName, _EventLogName)
End If
'*** Set the event log source ***
oEventLog.Log = _EventLogName
oEventLog.Source = _EventSourceName
'*** Write to the event log ***
oEventLog.WriteEntry(_EventSourceName, DisplayMessage,
objEventLogEntryType, EventID, Category)
End Sub
'**********************************************************************
'*** DESCRIPTION: Creates "Variable Information" entry. This is
'*** mainly used for testing purposes.
'**********************************************************************
Public Sub Message( _
ByVal Value As String, _
Optional ByVal objEventLogEntryType As EventLogEntryType =
EventLogEntryType.Information, _
Optional ByVal EventID As Integer = 0, _
Optional ByVal Category As Short = 0 _
)
'*** Declare Variables ***
Dim strMessage As String
'*** Initialize Variables ***
strMessage = "Message" & vbCrLf & vbCrLf
strMessage &= Value & vbCrLf
'*** Add Application Log Entry ***
Add(strMessage, objEventLogEntryType, EventID, Category)
End Sub
End Class
'***************************************
'*** MY FUNCTION CALL ***
'***************************************
Dim oApplicationEntry As New MyClass
oApplicationEntry.Message("TEST", EventLogEntryType.Error, 9999)
oApplicationEntry = Nothing
the logs to go to an EventLog I have created. However, I am finding that
the event is not logging to the created EventLog instead it is logging to
Application log. What could be the problem?
========================================================================
SYSTEM DETAILS:
========================================================================
Operating System: Windows 2000 Professional SP4
..NET Version: 1.1.4322
========================================================================
CODE:
========================================================================
Public Class MyClass
Private _EventSourceName As String = "MySource"
Private _EventLogName As String = "MyLog"
'**********************************************************************
'*** DESCRIPTION: Adds entries to the Application Log.
'**********************************************************************
Private Sub Add( _
ByVal DisplayMessage As String, _
ByVal objEventLogEntryType As EventLogEntryType, _
ByVal EventID As Integer, _
ByVal Category As Short _
)
'*** Create new event log ***
Dim oEventLog As New EventLog
'*** If the the Event Log does not exist, then create one.
If Not oEventLog.SourceExists(_EventSourceName) Then
'*** Create Log ***
oEventLog.CreateEventSource(_EventSourceName, _EventLogName)
End If
'*** Set the event log source ***
oEventLog.Log = _EventLogName
oEventLog.Source = _EventSourceName
'*** Write to the event log ***
oEventLog.WriteEntry(_EventSourceName, DisplayMessage,
objEventLogEntryType, EventID, Category)
End Sub
'**********************************************************************
'*** DESCRIPTION: Creates "Variable Information" entry. This is
'*** mainly used for testing purposes.
'**********************************************************************
Public Sub Message( _
ByVal Value As String, _
Optional ByVal objEventLogEntryType As EventLogEntryType =
EventLogEntryType.Information, _
Optional ByVal EventID As Integer = 0, _
Optional ByVal Category As Short = 0 _
)
'*** Declare Variables ***
Dim strMessage As String
'*** Initialize Variables ***
strMessage = "Message" & vbCrLf & vbCrLf
strMessage &= Value & vbCrLf
'*** Add Application Log Entry ***
Add(strMessage, objEventLogEntryType, EventID, Category)
End Sub
End Class
'***************************************
'*** MY FUNCTION CALL ***
'***************************************
Dim oApplicationEntry As New MyClass
oApplicationEntry.Message("TEST", EventLogEntryType.Error, 9999)
oApplicationEntry = Nothing