Solved

Writing to the Event Log vb net

Posted on 2013-06-13
9
471 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
  • 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
 

Author Comment

by:jmsjms
ID: 39255530
Sounds good!  Can this be done with the LE version of install shield?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Vb.net dynamic formulas in runtime 11 61
Word Directory is not in the drop down list 4 24
Turn on intranet settings 1 36
Advice on Xojo as a development tool over VB. 4 31
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

948 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now