Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I'm developing a windows service that makes use of windows event log to record its activities. I have created the setup project to install this windows service. When I tried to install this windows service. the installer started but failed with
error 1001: Source <servicename> already exist.


I suspect that event log is causing this problem, so i removed it from windows service and the service will install and run without any problem.. But i want to log the service activities, so I put the event log back into the windows service, look to my event viewer, and guess what: There is an event log file with the same log name and source..

So this is what i do:
I use EventLog.DeleteEventSource(source) and EventLog.Delete(logName) to delete the existing log file and source.

Again I look into event viewer and I couldn't find that particular log file.

Then I tried to install the windows service, the installer started and this time it didn't fail..

However... new problem comes out.. When I tried to start the service, it will immediately stop. It seems that, again, the event log is the one causing problem since I didn't face this problem when i took out the event log control from my windows service..

Using different logName and source for the event log control will actually solve the problem.. But...

I do not want to use different logName and source....... If anyone knows how to solve this problem without changing the logName and source, please share with me.. I really appreciate it..

Best Regards,
Paulus
Posted
Updated 2-Jun-11 19:43pm
v3
Comments
sirius007greatstar 6-Jun-11 21:12pm    
Finally solved this..

Uninstall the event log and source using SAKryukov's helper, delete the .evtx file, and then slightly changed my service name as suggested in thatraja's link..

After all of this, the installation works fine and the service runs with no problem..

Best Regards,
Paulus

Installation and uninstallation of a custom event source has a pretty complex logic, so it is quite easy to make a mistake is some scenarios. It's hard to find out what was your problem without looking at your code; and it would be difficult for you to create a short code sample suitable for the post in your question yet manifesting the problem. Let's try another way first.

I use some code to structure event logging per different application of the software product and shared a small wrapper which demonstrates right techniques. In particular, is shows how to setup and clean-up.
Please see my past answer here:

How to create event log under a folder[^].

I hope it will help you to see how to do it right. If you still cannot solve a problem, you will need to do a good for making the code sample I mentioned above. If you have some exception, don't forget to dump it (in file), output Exception.Stack and all inner exceptions (recursively) and mark all relevant lines in your source code. By the way, chances are, when you do all these preparations you will clearly understand your problem by yourself and will be able to solve it.

—SA
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900