【发布时间】:2015-11-26 15:58:03
【问题描述】:
问题是当主机重新启动(Windows 重新启动)或关闭(Windows 关闭)时,没有任何内容写入日志。
我在 Windows 服务中有以下内容:
protected override void OnStart(string[] args)
{
eventLogUtility.WriteToEventLog("Service has Started.", EventLogEntryType.Information);
}
protected override void OnStop()
{
eventLogUtility.WriteToEventLog("Service has Stopped.", EventLogEntryType.Information);
}
/// <summary>When implemented in a derived class, executes when the system is shutting down.
/// Specifies what should occur immediately prior to the system shutting down.</summary>
protected override void OnShutdown()
{
eventLogUtility.WriteToEventLog("Service has Shutdown.", EventLogEntryType.Information);
}
服务启动时,“服务已启动”。被写入日志。
当我停止服务时,“服务已停止”。被写入日志。
附:使用 .Net 4.5
【问题讨论】:
-
我不是 100% 确定,因为我不是服务人员,但我不认为
OnShutdown总是涵盖重新启动。尝试使用SessionEnded方法而不是shown here。 -
@Equalsk 感谢您的帮助,但我忘了输入问题文本,它不仅仅是重新启动......关机也不起作用......我现在已经编辑了......标题确实说关机/重启
-
嗯...测试...看起来可能是由于它在哪个帐户下运行...social.msdn.microsoft.com/Forums/vstudio/en-US/…
-
不,没有任何区别......仍然没有使用(域)管理员帐户写入日志,作为系统登录或作为服务登录......没有写入任何内容。呸呸呸
标签: c# .net windows service windows-services