New Message on dotNET User Group Hyd

Article :- Windows Services Part - 3

Reply
  Reply to Sender   Recommend Message 1 in Discussion
From: Nasha

Hey Group,

After creating our windows service today we will see how we can add event logging to it.

You can view all the existing event logs with event viewer (control panel -> administrative tools -> event viewer ).

You will basically fined 3 types of logs application, system and security.

To add EventLogging to our service.

Go to design mode of your windows service ... from components drag and drop eventlog name it as moveFileEventlog

Set the auto log property of your service to false (We had set this to true initially refer part 1)

Set the log and source properties of your log to Application and MoveFiles as below

                        this.moveFileEventLog.Log = "Application";
                        this.moveFileEventLog.Source = "MoveFiles";                    

Go to all the events of your service like Onstart,OnPause,OnStop and OnContinue and add a message line as shown below.

                protected override void OnStart(string[] args)
                {
                        oMoveFile = new MoveFile();
                        moveFileEventLog.WriteEntry("MoveFiles Service Started",EventLogEntryType.Information);
                }
                protected override void OnPause()
                {
                        moveFileEventLog.WriteEntry("MoveFiles Service Paused",EventLogEntryType.Information);
                        oMoveFile.PauseMoving();
                }
                protected override void OnStop()
                {
                        moveFileEventLog.WriteEntry("MoveFiles Service Stopped",EventLogEntryType.Information);
                        oMoveFile.StopMoving();                
                }

                protected override void OnContinue()
                {
                        moveFileEventLog.WriteEntry("MoveFiles Service Resumed",EventLogEntryType.Information);
                        oMoveFile.ResumeMoving();
                }


Now go back to the design mode of your service to add installer for your log.

Select your event log... Check out its properties.... Below its properties there is an add installer link.

This will add an eventloginstaller in your project installer class.

Build uninstall the older version if installed and then reinstall your service.

Check out the application log in the even viewer will find the start message.

Try to pause and resume the service; its corresponding event log messages will be registered.

-- Please post your queries and comments for my articles in the user group for the benefit of all. I hope this step from my end is helpful to all of us.

Regards,

Namratha (Nasha)
<o:p></o:p>


View other groups in this category.


Also on MSN:
Start Chatting | Listen to Music | House & Home | Try Online Dating | Daily Horoscopes

To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings.

Need help? If you've forgotten your password, please go to Passport Member Services.
For other questions or feedback, go to our Contact Us page.

If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list.
Remove my e-mail address from dotNET User Group Hyd.

Reply via email to