473,396 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem creating event log

I hope this is just something stupid I'm missing and someone can easily point
out my error. I'm trying to do a few turorials on windows services, and the
couple I found so far just create an event log and write an entry on start
and stop. I build the projects and install them fine, but when I run the
service it starts and stops instantly. The service is not creating the
custom event log I wanted it to but instead adds an error message in the
Application event log saying that the source I declared for my eventlog was
not registered to the eventlog I declaired. I'm not sure I understand
because I found several articles on line saying if you included a custom
source and log for an EventLog component, if they were not present they were
automatically created. Here is the code I use to intialize the event log:

Public Sub New()
MyBase.New()

' This call is required by the Component Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call
' Test if the event log exists; if not, create it
If (Not System.Diagnostics.EventLog.SourceExists("ServiceO ne")) Then
EventLog.CreateEventSource("ServiceOne", "ServiceOneLog")
End If
' Set the source and log properties for the event log
EventLog1.Source = "ServiceOne"
EventLog1.Log = "ServiceOneLog"
End Sub

Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
EventLog1.WriteEntry("ServiceOne is starting.")
End Sub

I'm not sure why this is failing. All the examples I find say this should
work. Do I need to set something up to be allowed to create an event log?
I've tried setting up the service as both a local service and as a service
under an admin user with now luck? Can anyone give me any advice on what I'm
missing?

Chris
Feb 13 '06 #1
3 1380
I hit the same wall and after some debugging found out that the service
did not have the correct security rights to create a event log.

You can change the security setting, but after some searching quite some
people recomemded creating the event log during the install (Custom Action).

This is the point that I'm at. If I get it to work 100% I will let you
know.

Here are some links I have used so far:

http://msdn.microsoft.com/library/de...classtopic.asp

http://msdn.microsoft.com/library/de...Installers.asp

Nick
clsmith66 wrote:
I hope this is just something stupid I'm missing and someone can easily point
out my error. I'm trying to do a few turorials on windows services, and the
couple I found so far just create an event log and write an entry on start
and stop. I build the projects and install them fine, but when I run the
service it starts and stops instantly. The service is not creating the
custom event log I wanted it to but instead adds an error message in the
Application event log saying that the source I declared for my eventlog was
not registered to the eventlog I declaired. I'm not sure I understand
because I found several articles on line saying if you included a custom
source and log for an EventLog component, if they were not present they were
automatically created. Here is the code I use to intialize the event log:

Public Sub New()
MyBase.New()

' This call is required by the Component Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call
' Test if the event log exists; if not, create it
If (Not System.Diagnostics.EventLog.SourceExists("ServiceO ne")) Then
EventLog.CreateEventSource("ServiceOne", "ServiceOneLog")
End If
' Set the source and log properties for the event log
EventLog1.Source = "ServiceOne"
EventLog1.Log = "ServiceOneLog"
End Sub

Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
EventLog1.WriteEntry("ServiceOne is starting.")
End Sub

I'm not sure why this is failing. All the examples I find say this should
work. Do I need to set something up to be allowed to create an event log?
I've tried setting up the service as both a local service and as a service
under an admin user with now luck? Can anyone give me any advice on what I'm
missing?

Chris

Feb 13 '06 #2
I hit the same wall but after some debugging found out that the service
did not have the correct security rights to create a event log.

You can change the security setting, but after some searching quite some
people recommended creating the event log during the install (Custom
Action).

This is the point that I'm at. If I get it to work 100% I will let you
know.

Here are some links I have used so far:

http://msdn.microsoft.com/library/de...classtopic.asp

http://msdn.microsoft.com/library/de...Installers.asp

Nick
clsmith66 wrote:
I hope this is just something stupid I'm missing and someone can easily point
out my error. I'm trying to do a few turorials on windows services, and the
couple I found so far just create an event log and write an entry on start
and stop. I build the projects and install them fine, but when I run the
service it starts and stops instantly. The service is not creating the
custom event log I wanted it to but instead adds an error message in the
Application event log saying that the source I declared for my eventlog was
not registered to the eventlog I declaired. I'm not sure I understand
because I found several articles on line saying if you included a custom
source and log for an EventLog component, if they were not present they were
automatically created. Here is the code I use to intialize the event log:

Public Sub New()
MyBase.New()

' This call is required by the Component Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call
' Test if the event log exists; if not, create it
If (Not System.Diagnostics.EventLog.SourceExists("ServiceO ne")) Then
EventLog.CreateEventSource("ServiceOne", "ServiceOneLog")
End If
' Set the source and log properties for the event log
EventLog1.Source = "ServiceOne"
EventLog1.Log = "ServiceOneLog"
End Sub

Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
EventLog1.WriteEntry("ServiceOne is starting.")
End Sub

I'm not sure why this is failing. All the examples I find say this should
work. Do I need to set something up to be allowed to create an event log?
I've tried setting up the service as both a local service and as a service
under an admin user with now luck? Can anyone give me any advice on what I'm
missing?

Chris

Feb 13 '06 #3
Hi Chris,

Try impersonating the service to run under admin account. And I'm using
the below code, it works fine.

' creation of event log if it does not exist
Dim eventLogName As String = "PROS"
If Not EventLog.SourceExists(eventLogName) Then
EventLog.CreateEventSource(eventLogName, eventLogName)
End If

' insert into eventlog
Dim log As New EventLog()
log.Source = eventLogName
log.WriteEntry(errorDescription, EventLogEntryType.Error)

Cheers,
Kris

Feb 13 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: RJS | last post by:
Hi all, I can't get a py2exe compiled app to run with numarray (numarray-0.5.win32- py2.2). Also wxPythonWIN32-2.3.3.1-Py22 and ActivePython-2.2.1-222. In the sample below, commenting out...
3
by: vinayak | last post by:
Hi I am displaying data in Datagrid in ASP.NET with Edit/Update functionality for each row. On the same page I have 2 Button controls which submits the request to server. These button controls...
6
by: Robin Bonin | last post by:
In my user contol I am creating a set of dropdownlists. Each list is created based on input from the other lists. The problem I am having is setting the selected index on the lists. If someone...
14
by: Venkat Chellam | last post by:
I have a peculiar problem. I have a simple web application which loads some data from the oracle table and display in the datagrid in the webpage and datagrid has page enabled which shows 10 rows...
9
by: Anders K. Jacobsen [DK] | last post by:
Hi I have this that adds some usercontrol (UCTodays.ascx) to a placeholder foreach(A a in B){ UCTodays ucline = (UCTodays )LoadControl("UCTodays.ascx");...
5
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...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
9
by: =?Utf-8?B?YmJn?= | last post by:
Hi all, I read somewhere "using kernel stuff in thread is not good.." if ManualResetEvent object is created in thread but not actually used, will it affect performance? Bob
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.