Solved

Writing to the Event Log vb net

Posted on 2013-06-13
9
479 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

808 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