我正在使用以下 XML 查询从事件查看器中读取过去 24 小时内的系统“开启事件”。
string query = "<QueryList>" +
"<Query Id=\"0\" Path=\"System\">" +
"<Select Path=\"System\">*[System[(EventID=6005) and TimeCreated[timediff(@SystemTime) <= 86400000]]]</Select>" +
"</Query>" +
"</QueryList>";
它在 Windows 7 及更高版本上运行良好,但在 Windows XP 上,我收到以下错误:
Error:Operation is not supported on this platform
有人可以帮助从 C#.net 中的事件查看器读取 Windows XP 中的 Turn On 事件吗?
最佳答案
XPpath
过滤首先出现在 Vista
中。对于 XP
,您将不得不使用另一个实现 EventLog
class .
EventLog aLog = new EventLog();
aLog.Log = "Application";
aLog.MachineName = "."; // Local machine
string message = "\'Service started\'";
foreach (EventLogEntry entry in aLog.Entries)
{
if (entry.Source.Equals("tvNZB")
&& entry.EntryType == EventLogEntryType.Information)
{
if (entry.Message.EndsWith(message))
{
//write it somewhere
}
}
}
关于c# - 如何在 C#.net 中读取 Windows XP 中的事件查看器日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39392136/