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();
}
过滤器是XPath
和XQuery
.如果你想了解事件的内部结构,我发现最好通读 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...
这篇关于阅读事件查看器条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:阅读事件查看器条目


- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 如何用自己压缩一个 IEnumerable 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01