Solved

Writing to the Event Log vb net

Posted on 2013-06-13
9
486 Views
Last Modified: 2013-06-24
Hi,  I'm trying to write to the event log in a Windows Service Application I'm developing.

The Service builds OK. But the service just stops as soon as it starts without any logging.


Any idea?

    If Not System.Diagnostics.EventLog.SourceExists("MyService") Then
      System.Diagnostics.EventLog.CreateEventSource("NyService", "MyService Log")
    End If

    _eventLog = New EventLog()
    _eventLog.Source = "MyService"
    _eventLog.WriteEntry(" Service started.", EventLogEntryType.Information)
0
Comment
Question by:jmsjms
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 39244357
is this code inside OnStart() function in your window service class?
do u have exception handling on your code to detect errors?
you can also use Debugger.Break() inside the class in order to debug the code when the service starts.
0
 

Assisted Solution

by:jmsjms
jmsjms earned 0 total points
ID: 39253583
Couldnt get it to work.

Looks like an application needs to have admin rights to use the CreateEventSource function and the service I have created hasnt got it.

If anyone has sample code to use Event logs in Services that actually works without running the server as admin please let me know!
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39253587
You can create event source as part of the setup which has to be run as admin and then just log events in the service.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jmsjms
ID: 39255530
Sounds good!  Can this be done with the LE version of install shield?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39257828
Not sure. You can create another exe which you can ask user to launch as admin when you find out, in your main program, that event source does not exist.
0
 

Author Comment

by:jmsjms
ID: 39258615
But you cant have any user-interaction with a service so how could you do this?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39260333
There are work arounds but i think first thing to do is to determine if installshield LE can help you.
0
 

Author Comment

by:jmsjms
ID: 39261731
I've run out of time to devote to this, so cant confirm whether installsheild LE can help here of not.

I'll mark this as an answer so people can see what I found out and one possible way forward.
0
 

Author Closing Comment

by:jmsjms
ID: 39270725
My comment indicates that just getting a service to create the event log source will not work (despite some examples on the web) UNLESS the service has admin rights.

Codecruisers suggestion that it's done as part of the installation is a good idea but I can't confirm this works yet.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question