阅读事件查看器条目

Read event viewer entries(阅读事件查看器条目)
本文介绍了阅读事件查看器条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 c# 程序中从某个自定义事件日志中读取事件条目,并通过他们的描述过滤它们.有没有办法做到这一点?还是一种将条目作为集合获取的方法,以便我可以按条件从中进行选择?

I want to read event entries from a certain custom event log at c# program, And to filter them by their description. Is there a way to do it? Or a way to get the entries as collection so I will be able to select from that by condition?

推荐答案

试试这样的:

       string queryString = string.Format("*[System[TimeCreated[@SystemTime>='{0}' and @SystemTime<='{1}']]]",
            DateTime.Now.Date.AddDays(-10).ToString("s"),
            DateTime.Now.Date.ToString("s"));
        var q = new EventLogQuery("Microsoft-Windows-User Profile Service/Operational", PathType.LogName, queryString);
        var r = new EventLogReader(q);

        var list = new List<EventRecord>(); 

        EventRecord er = r.ReadEvent();
        while (er != null) {
            list.Add(er);
            er = r.ReadEvent();
        }

过滤器是XPathXQuery.如果你想了解事件的内部结构,我发现最好通读 eventvwr 中的过滤器定义.查看 XML-tab...

The filter is XPath and XQuery. If you want to learn about an events internal structure I found it best to read through the filter definition within eventvwr. Look into the XML-tab...

这篇关于阅读事件查看器条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)