Click here to Skip to main content
15,891,621 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to log the activities when a windows service is started or stopped. How I can do that? Is it possible to send email alert, when a service is changed it state?
Posted

Since .NET 2.0:
By default, all Windows Service projects have the ability to interact with the Application event log and write information and exceptions to it. You use the AutoLog property to indicate whether you want this functionality in your application. By default, logging is turned on for any service you create with the Windows Service project template. You can use a static form of the EventLog class to write service information to a log without having to create an instance of an EventLog component or manually register a source.

The installer for your service automatically registers each service in your project as a valid source of events with the Application log on the computer where the service is installed, when logging is turned on. The service logs information each time the service is started, stopped, paused, resumed, installed, or uninstalled. It also logs any failures that occur. You do not need to write any code to write entries to the log when using the default behavior; the service handles this for you automatically.
[^]
 
Share this answer
 
I was thinking

a) monitor the windows event log(s) and filter out log events for your service or

b) write a service that interacts with the SCM on the machine your watched service is running on through System.ServiceProcess.ServiceController - have a look at Jarowslaw's answer here http://stackoverflow.com/questions/14341234/remote-controlling-of-windows-service-installed-on-intranet-machine[^]

I also write services with an inbuilt 'heartbeat' broadcast via UDP, and a watcher running elsewhere in the network
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900