如何在C#中重启或关闭Windows日志 [英] How to log windows restart or shutdown in C#

查看:83
本文介绍了如何在C#中重启或关闭Windows日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我的应用程序一旦启动,将永远在系统托盘中运行。它还记录了应用程序中发生的所有事件。现在我有一个要求是"如果用户关闭或重新启动系统,我的应用程序必须在日志文件(文本文件)中记录
日志。"如何在C#.net 2.0中完成。

My application will be running in system tray forever once it is been launched. And also it is logging all events occurred in application in text file. Now I got one requirement is that "If user shut down or restart the system, my application has to log regarding this in log file(text file)." How can I do it in C# .net 2.0.

我们将不胜感激。

最诚挚的问候,

Best Regards,

Hari

点击"建议作为答案"如果这篇文章解决了你的问题或"投票有帮助"如果一篇文章对你有用,快乐编程! Hari

click "Proposed As Answer by" if this post solves your problem or "Vote As Helpful" if a post has been useful to you Happy Programming! Hari

推荐答案

您好Hariprasadbrk,

Hi Hariprasadbrk,

感谢您在此发帖,

对于您的问题,您可以尝试使用PowerModeChanged事件。

For your question, you could try to use PowerModeChanged Event.

当用户挂起或恢复操作系统或系统电源状态时,会引发PowerModeChanged事件通知发生。当检测到弱电或充电电源时,或者当AC或电池电源发生转换
时,可能会发生系统电源状态通知。

A PowerModeChanged event is raised when the user suspends or resumes the operating system, or when a system power status notification occurs. A system power status notification can occur when a weak or charging power source is detected, or when a transition from AC or battery power source occurs.

有关详细信息,您可以请参阅MSDN文章。

For more details, you could refer to the MSDN article.

https://msdn.microsoft.com/en-us/library/microsoft.win32.powermodechangedeventargs(v = vs.110).aspx

Best问候,

Wendy


这篇关于如何在C#中重启或关闭Windows日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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