Add entry to event log inside a service : EventLog : Windows C# Examples


C# Examples » Windows » EventLog »

 

Add entry to event log inside a service









    
using  System;
using  System.Collections;
using  System.ComponentModel;
using  System.Data;
using  System.Diagnostics;
using  System.ServiceProcess;

public  class  Service1  :  System.ServiceProcess.ServiceBase
{

    public  Service1()
    {
        this.ServiceName  =  "MyFirstService";
    }

    static  void  Main()
    {
        System.ServiceProcess.ServiceBase[]  ServicesToRun;
        ServicesToRun  =  new  System.ServiceProcess.ServiceBase[]  {  new  Service1()  };

        System.ServiceProcess.ServiceBase.Run(ServicesToRun);
    }
    protected  override  void  OnStart(string[]  args)
    {
        EventLog.WriteEntry(  "Hello  from  MyFirstService"  );
    }

    protected  override  void  OnStop()
    {
        EventLog.WriteEntry(  "Goodbye  from  MyFirstService"  );
    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Windows
» EventLog