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
--
Thanx in Advance,
atr2000 2 1531
Hi John,
The issue I see is with the statement '*** 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
The default project installer action creates the event source in the
"Application" log, So the "SourceExists" would always return true and the
"CreateEventSource" statement would never get executed. If this is indeed a
service then I'd recommend you use the Me.EventLog option
(ServiceBase.EventLog) to set the source & Log for logging messages.
--
Ravi Shankar
"John Smith" wrote:
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
-- Thanx in Advance,
atr2000
Ravi,
Thank you for the idea but unfortunately that did not help. However I did
figure it out. I changed the code to more like the following.
'*** Create new event log ***
Dim oEventLog As New EventLog
'*** Since I know that my log name is unique, I am not afraid to remove
the source registration from the Application log ***
If oEventLog.LogNameFromSourceName(_EventSourceName,
Environment.MachineName).ToLower <> _EventLogName.ToLower Then
'*** Delete Source ***
oEventLog.DeleteEventSource(_EventSourceName)
End If
'*** If the the Event Log does not exist, then create one. ***
If oEventLog.Exists(_EventLogName) = False Or
oEventLog.SourceExists(_EventSourceName) = False Then
'*** Create Log ***
oEventLog.CreateEventSource(_EventSourceName, _EventLogName)
End If
..... Etc....
--
Thanx,
atr2000
"Ravi Shankar" <sh*********@newsgroup.nospam> wrote in message
news:74**********************************@microsof t.com... Hi John,
The issue I see is with the statement '*** 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 The default project installer action creates the event source in the "Application" log, So the "SourceExists" would always return true and the "CreateEventSource" statement would never get executed. If this is indeed
a service then I'd recommend you use the Me.EventLog option (ServiceBase.EventLog) to set the source & Log for logging messages. -- Ravi Shankar
"John Smith" wrote:
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
-- Thanx in Advance,
atr2000 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jacob Colding |
last post by:
Hello,
I have created a a logging mechanism, that writes mesages to a custom event
log. On each check it verifies whether the requested source is registered to
the "IPS" log. If not, it changes...
|
by: Alex |
last post by:
I am trying to write an Exit module for the Certification server in VB.NET
and I cant get the module to be recognised by the Certification MMC snap in.
Its function is to capture Serial Numbers of...
|
by: Ronald Moolenaar |
last post by:
Hi,
My colleague implemented a class overwriting TextWriter. What he tried
to do was logging to the event logger and logging to console. As you
can see in the code below, the part of 'logging to...
|
by: Jassim Rahma |
last post by:
Hi,
I am trying to create an eventlog DLL which uses vistaDB but I have a
problem calling it.. can you please help...
the DLL:
using System;
|
by: Dan Brill |
last post by:
Hi,
I'm sure this issue has been covered before but after searching around I
can't find anything which deals with quite the same set of circumstances or
suggests an optimal solution.
The...
|
by: Brian Henry |
last post by:
Has security changed with accessing the event log through a local service in
..NET 2.0? in 1.1 i did this
If Not Diagnostics.EventLog.SourceExists("BDBHOST") Then
' create log
...
|
by: Ben |
last post by:
I modified the logmonitor sdk example so it would work over a network. It
works great when the client and server are running on the same PC and have
administrator privileges. So I have two...
|
by: Dave Raskin |
last post by:
I am self hosting a Web Service in a Windows service. I am trying to start
the service using the NT AUTHORITY\NetworkService account.
I get a NullReferenceException on ServiceHost.Open() in the...
|
by: Dave Burns |
last post by:
I am self hosting a Web Service in a Windows service. I am trying to start
the service using the NT AUTHORITY\NetworkService account.
I get a NullReferenceException on ServiceHost.Open() in the...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |