Event Viewer — log to sub folder?

2019-07-15 12:46发布

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?

1条回答
叛逆
2楼-- · 2019-07-15 13:30

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"

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.

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

查看更多
登录 后发表回答