c# - 如何在 C#.net 中读取 Windows XP 中的事件查看器日志

标签 c# event-viewer

我正在使用以下 XML 查询从事件查看器中读取过去 24 小时内的系统“开启事件”。

string query = "<QueryList>" +
                "<Query Id=\"0\" Path=\"System\">" +
                "<Select Path=\"System\">*[System[(EventID=6005) and TimeCreated[timediff(@SystemTime) &lt;= 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 .

Example:

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/

相关文章:

c# - 重载构造函数 C#

c# - 在 C# 中使用计时器实现循环

c# - Windows 事件查看器中未显示新的 Windows 日志

batch-file - 如何在每次启动时自动将我的事件日志导出到文件夹(csv 或 txt)?

c# - 事件查看器,如何以编程方式向其添加 “task”

c# - 在 Azure 中使用事件日志(在事件查看器中写入)

c# - 使用 For-Each 循环创建 TableView

c# - 什么是 x-wmapp2 和 x-wmapp1?

C# 编译器缺陷? : Not detecting methods that always throw exceptions

c# - .Net Windows 服务崩溃并出现 MSVCR120_CLR0400.dll 异常