在我的一个项目中,我需要检查机器上是否存在事件日志“Microsoft-Exchange-ManagedAvailability/Monitoring”(事件源是 ManagedAvailability)。
我用过
EventLog.Exists("Microsoft-Exchange-ManagedAvailability/Monitoring")
和
EventLog.SourceExists("ManagedAvailability")
两者都返回false,但是事件日志确实存在。它位于“应用程序和服务日志”/Microsoft/下,请参见屏幕截图。
那么,如何查看这个日志是否存在呢?
谢谢
最佳答案
EventLog.Exists()
似乎只支持经典事件日志,不支持 new-since-Vista hyphenated-format-with-slash 格式。 Process Monitor表明它试图打开 HKLM\System\CurrentControlSet\Services\EventLog\Microsoft-Exchange-ManagedAvailability/Monitoring
,它不存在 - 它在 HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WINEVT\Channels\Microsoft-Windows-SENSE/Operational
.
所以我猜你要么必须尝试打开并捕获失败异常(丑陋),要么获取所有事件日志的列表并找到你的:
EventLogSession.GlobalSession.GetLogNames().Any(
s => string.Equals(s, "Microsoft-Exchange-ManagedAvailability/Monitoring", StringComparison.OrdinalIgnoreCase))
关于c# - 如何查看此事件日志是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34601030/