事件查看器-登录到子文件夹? [英] Event Viewer — log to sub folder?

查看:67
本文介绍了事件查看器-登录到子文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了并且找不到答案.我们有一个运行并登录到事件查看器的自定义服务.在Windows 7中,有一个名为应用程序和服务日志"的文件夹.如何在其中记录事件?甚至有可能吗?

I've searched and searched and can't find the answer. We have a custom service that runs and logs into the Event Viewer. In Windows 7, there's a folder called "Applications and Services Logs". How do I log an event in there? Is it even possible?

推荐答案

当您使用以下方法创建新的事件日志时,它将自动发生:

It will happen automatically when you create a new Event Log using something like:

EventLog.CreateEventSource("Our Source", "Our Log");

然后,该调用需要提升的特权,但只需要执行一次即可.之后,您可以使用普通权限进行引用.

And that call requires elevated privileges, but only needs to be done once. After that, you can reference with normal privileges using.

EventLog _eventLog = new EventLog("Our Log"); // Writes to OUR event log--NOT the system created "Application"

注意:如果要将源从Application移至自定义日志,则可能需要进行一些调整和/或重新启动,因为将源从一个日志移至另一日志是不正常的.

Note: If you are moving your source from Application to your custom log, it may need some tweaking and/or a reboot as it is not normal to move a source from one log to another.

如果使用的是InstalUtil,还可以使用System.Diagnostics.EventLogInstaller

If you are using InstalUtil, you can also create the log using a System.Diagnostics.EventLogInstaller

这篇关于事件查看器-登录到子文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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