Re: Windows Services

From: Jay B. Harlow [MVP - Outlook] (Jay_Harlow_MVP_at_msn.com)
Date: 05/17/04


Date: Mon, 17 May 2004 12:25:33 -0500

Eric,
Which of the following event log messages are you seeing?
> Log.WriteEntry("FusionDec démarrer avec succès")
> Log.WriteEntry("Erreur lors du démarrage du service : " &
vbCrLf & ex.ToString)

Depending on which you see will indicate if your service is starting or not.

If you are not seeing either then the OnStart is not being reached or is
terminating early.

Are you calling MyBase.OnStart from your OnStart?

More importantly! As I stated, put a try catch in your FusionDec method, so
you know if it failed or not, plus put logging to know it was called.

This way you if you see the success message you know the service started,
then you can look for the FusionDec messages, so you know

You do know that you can have the Windows Installer create the Event Source
& Event Log for you?

> 'Création des logs s'il n'existe pas.
> If Not Log.SourceExists("FusionDec") Then
> Log.CreateEventSource("FusionDec", "FusionDec")
> End If
> Log.Source = "FusionDec"

Drag an EventLog object from the toolbox onto the design surface of your
Windows Service. Set the Log & Source properties. Click the "Add Installer"
link (or right click on EventLog on the designer). This will add an
Installer to your Service Installer.

Also, rather then using your Log property I override the
ServiceBase.EventLog property and return the object created by dragging an
EventLog to the designer. This causes all the automatic messages as well as
my messages to go to the same log. (read you can leave AutoLog=True and the
auto log messages will go to the event log of your choosing).

    Public Overrides ReadOnly Property EventLog() As
System.Diagnostics.EventLog
        Get
            Return Me.EventLog1
            ' Seeing as you have a Log property you can return it.
            Return Log
        End Get
    End Property

Then I would simply use EventLog

> EventLog.WriteEntry("FusionDec démarrer avec succès")
> EventLog.WriteEntry("Erreur lors du démarrage du service : " &
vbCrLf & ex.ToString)

Hope this helps
Jay

"Eric" <anonymous@discussions.microsoft.com> wrote in message
news:6D80D955-B494-4E88-B5F4-B90630574814@microsoft.com...
> Hi,
>
> This is what I have in my OnStart :
>
> Try
> EcrireErreur("test")
> 'Création des logs s'il n'existe pas.
> If Not Log.SourceExists("FusionDec") Then
> Log.CreateEventSource("FusionDec", "FusionDec")
> End If
> Log.Source = "FusionDec"
>
> 'option du FileSystemWatcher.
> fwFichierFusion.Path = "c:\Test2\"
> fwFichierFusion.Filter = ""
> fwFichierFusion.IncludeSubdirectories = True
>
> fwFichierFusion.EnableRaisingEvents = True
>
> 'Ajout de l'action évènement.
> AddHandler fwFichierFusion.Created, AddressOf FusionDec
>
> Log.WriteEntry("FusionDec démarrer avec succès")
> Catch ex As Exception
> Debug.WriteLine(Err.GetException.ToString())
> EcrireErreur(Err.GetException.ToString())
> Log.WriteEntry("Erreur lors du démarrage du service : " &
vbCrLf & ex.ToString)
> End Try
>
>
> I think it isn't to much in the OnStart() and I can't debug it because it
start and few second after it stop.
>
> by the way thanks for trying



Relevant Pages

  • RE: Setting category / event ID when tracing in VS2008
    ... To learn how to specify category for the event log entry, ... Now we can create an installer (you can choose to add the installer to your ... Public Class MyEventLogInstaller ... Now we can use the EventLog class in .NET Framework to write an event log ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Service, Requested registry access is not allowed
    ... eventlog assuming that the user installing the service has appropriate ... write to a custom event log and work fun running under Network Service. ... In that case you don't even need the installer. ... "Requested registry access is not allowed" but I feel I went by the ...
    (microsoft.public.dotnet.security)
  • Re: Win2k3 Event Log and Security: Must choose between security and trustworthy
    ... Right-click the event log and select "Add Installer". ... > coding of the application developers create new sources. ... > This is clearly a security problem, but it solves the problem of being ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Event Log Trust Level?
    ... Any idea on what permissions to give ASPNET (registry ... I don't fancy the installer option. ... >What I do in this case is install the event log as part ... >> source, String logName, String machineName, Boolean ...
    (microsoft.public.dotnet.security)
  • Re: Windows Service AutoStart Problem (C#)
    ... > I have a problem on some machines to AutoStart a very simple windows service. ... > It just logs a line in the event log when the OnStart and OnStop occurs. ... > Event Source: Service Control Manager ... I think the problem may be that you try to write to the EventLog but the ...
    (microsoft.public.dotnet.framework.windowsforms)