473,651 Members | 2,644 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.
InitializeCompo nent()

' Add any initialization after the InitializeCompo nent() call
' Test if the event log exists; if not, create it
If (Not System.Diagnost ics.EventLog.So urceExists("Ser viceOne")) Then
EventLog.Create EventSource("Se rviceOne", "ServiceOneLog" )
End If
' Set the source and log properties for the event log
EventLog1.Sourc e = "ServiceOne "
EventLog1.Log = "ServiceOne Log"
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.Write Entry("ServiceO ne 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 1393
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.
InitializeCompo nent()

' Add any initialization after the InitializeCompo nent() call
' Test if the event log exists; if not, create it
If (Not System.Diagnost ics.EventLog.So urceExists("Ser viceOne")) Then
EventLog.Create EventSource("Se rviceOne", "ServiceOneLog" )
End If
' Set the source and log properties for the event log
EventLog1.Sourc e = "ServiceOne "
EventLog1.Log = "ServiceOne Log"
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.Write Entry("ServiceO ne 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.
InitializeCompo nent()

' Add any initialization after the InitializeCompo nent() call
' Test if the event log exists; if not, create it
If (Not System.Diagnost ics.EventLog.So urceExists("Ser viceOne")) Then
EventLog.Create EventSource("Se rviceOne", "ServiceOneLog" )
End If
' Set the source and log properties for the event log
EventLog1.Sourc e = "ServiceOne "
EventLog1.Log = "ServiceOne Log"
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.Write Entry("ServiceO ne 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.Source Exists(eventLog Name) Then
EventLog.Create EventSource(eve ntLogName, eventLogName)
End If

' insert into eventlog
Dim log As New EventLog()
log.Source = eventLogName
log.WriteEntry( errorDescriptio n, EventLogEntryTy pe.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
2983
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 "import numarray" allows the exe to run. Left in, I get "4.exe has generated errors" etc. I'm going around and around and there isn't much on Google. py2exe output is last.
3
4910
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 are Web Control & not HTML control. One of these buttons whose title is Delete is added on the aspx page in design view & also I double clicked on this button in design view to get the onclick code for this button in the code behind page. & for...
6
7003
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 changes box1, I want to set the selected index in box2 = 0. When I do this, I dont get an error, but when the page loads, it still has the selected value and not 0. It seems that it is getting the selected value from the viewstate
14
2255
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 at a page.I have a search criteria to search the records based on the data range i give This is what i have done, in the !IsPostBack section. I am setting up the oracle connection, creating dataset object, datadapter and i aslo load the data...
9
2444
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"); ucline.Initializecontrol(line,alternate); Placeholder1.Controls.Add(ucline); }
5
1637
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 issue is, broadly, that when I try to write to the Windows Event Log from ASP.NET code I receive a System.Security.SecurityException ("Requested registry access is not allowed").
10
4008
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 application. What should happen, is that the main MDI form should close, taking the child forms with it. There is code to loop through the child forms, remove the controls on each of them, and then close the form, but this code should execute only...
7
4811
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 expandable row, the hidden row is made visible with css. The problem is when i sort the rows, the hidden rows get sorted as well which i don't want and want to be moved (while sorting) relative to their parent rows. The following is my complete html code...
9
2975
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
8349
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8795
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8576
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7296
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4143
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4281
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1906
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.