Solved

Writing to the Event Log vb net

Posted on 2013-06-13
9
470 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video discusses moving either the default database or any database to a new volume.
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…

708 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

18 Experts available now in Live!

Get 1:1 Help Now