记录Windows服务 [英] Log a windows service

查看:55
本文介绍了记录Windows服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在启动或停止Windows服务时记录活动。我怎么能这样做?是否有可能发送电子邮件警报,当服务被更改时它状态?

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?

推荐答案

从.NET 2.0开始:
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.

[ ^ ]


我在想



a)监控窗户事件日志并过滤掉您的服务的日志事件或



b)编写一个服务,通过系统运行您正在运行的服务的计算机上与SCM交互.ServiceProcess.ServiceController - 看看Jarowslaw的回答 http: //stackoverflow.com/questions/14341234/remote-controlling-of-windows-service-installed-on-intranet-machine [ ^ ]



我也用内置的'他写服务artbeat通过UDP广播,以及在网络其他地方运行的观察者
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


这篇关于记录Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆