Handling Events and Logging Information from a Windows Service Application

Are you preparing for IT certification? With practice questions, study notes, interactive quizzes, tips and technical articles, uCertify PrepKits ensure that you get a solid grasp of core technical concepts to ace your certification exam in first attempt.

Handling Events and Logging Information from a Windows Service Application

Rating:

A Windows service application supports various customized events, such as changing the power status of a computer or logging information. The logging information can change the state of the service or errors in the system event logs and customize your event logs. By using the performance counter, you can also monitor the performance of your service. The events of a Windows service totally depend on the state of the service. Whenever the state of service changes, the corresponding event occurs. For example, if your service changes from a running state to a pause state, then the pause event occurs. A Windows service supports four events, namely start, stop, pause, and continue.

Start Event: This event occurs when you start a service using the SCM. The system locates the .EXE file and calls the OnStart() method for the service. By using the OnStart() method, you can set the service to start mode. The StartType property is used for this purpose.

Stop Event: This event occurs when you stop a service using the SCM. Then the OnStop() method is called, and the SCM checks the value of the CanStop property. The SCM can pass the stop command to the service, only if the CanStop property is set to true.

Pause Event: This event occurs when you pause your service while it is in the running state. When your service is in the pause state, the SCM checks the value of the CanPauseAndContinue property. The SCM sends a pause request to your service when the CanPauseAndContinue property is set to True, and then the OnPause() method is called.

Continue Event: This event occurs when you resume your service application that is paused. When a service is resumed from the pause state, the SCM checks the CanPauseAndContinue property. If this property is set to True, the SCM passes the Continue command to the service, and finally the OnContinue() method is called.

With the occurrence of various events in your service application, you can log, in the event logs, the information that can track the state of your service. The various event-logging features include the failure of a service, low-memory condition, or passing of a service, which can then determine the type and cause of the error. The event log component is used to write log entries that can be accessed on both local and remote computers. The following are the three types of event logs available in your service application:

System Log: The System Log consists of messages concerning the events that occur on system components such as device drivers.

Security Log: The Security Log consists of messages concerning the security changes.

Application Log: The Application Log consists of messages concerning the events that occur in an application installed on a computer.

To access and create entries in the system application, the AutoLog property of the ServiceBase class should be set to true. When you install your service application, the installer checks the value of the AutoLog property, and if the value is set to true, your service application gets registered by the installer in the Application log. After that, whenever your service is started, stopped, paused, resumed, installed, or uninstalled, your service automatically logs information.


Rating:



Other articles

Click here to Article home

 
uCertify.com | Our Company | Articles | Privacy | Security | Contact Us | News and Press Release | uCertify India
MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD Cisco Certification: CCNA, CCENT, A+, Network+, Security+
Oracle Certification: OCP 9i, OCP 10g, OCA 9i, OCA 10g CIW foundation    EC-212-32    CISSP    Photoshop ACE    Adobe Flash ACE
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.