c# - 和/或 XPath 查询以选择一些事件日志记录
问题描述
我用谷歌搜索了很多可能的答案,但没有运气。我正在尝试从事件日志(伪代码)中提取以下内容:
select events
where
event date/time between FromDateTime and ToDateTime
and
((Level<=2) // error, critical only
or
((Level<=x) and Provider[Name] in a specific list) // any messages for these apps
)
(第二个“Level”表达式是允许用户指定是包含Informal消息还是限制为Warnings及以上,所以我不能直接丢弃它。)
以下是我尝试使用的(最新)表达式 - 未成功。
string queryString =
"*[System[TimeCreated[@SystemTime>='" + dFrom + "' and @SystemTime<='" + dTo + "']]] " +
" and " +
"(*[System[Level<=2]]" +
" or " +
" ( " +
" *[System[Provider[@Name='<1st name>' or @Name='<2nd name>' or @Name='<3rd name>]] " +
" and " +
"System[Level<=" + maxLevel.ToString() + "]]" +
")" +
");"
我是否试图创建一个对于事件日志查询评估器来说太难的表达式,或者我只是在表达式中有一个简单的错误?我一直在尝试各种形式的表达。似乎“级别”过滤器只是被忽略了,但为什么呢?
解决方案
*** 啊!!- 我想我找到了。事件日志级别枚举为:
1 - Critical alert
2 - Error
3 - Warning
4 - Informational
5 - Logs at all levels
... and ...
0 - Undefined - indicates logs at all levels
事实证明,来自 Microsoft 组件的一些“信息”日志条目使用 0 级而不是 4 级,因此过滤器会拾取这些条目。我认为日志条目(尤其是 Microsoft 的)会使用适当级别的假设是错误的。
我需要明确查找(Level=1 或 Level=2)——Level <= 2 将获取各种 Microsoft“信息”日志条目。
对于任何有兴趣的人 - 最终的工作查询是:
*[System[TimeCreated[@SystemTime>='2018-07-30T17:22:30.000Z'
and @SystemTime<='2018-07-30T20:22:30.000Z']
and (Level=1 or Level=2 or
(Provider[@Name='Application Error' or @Name='Application Hang']
and (Level=1 or Level=2 or Level=3 or Level=4)))]]
推荐阅读
- docker - 如何在 Gitlab 上要求 Docker 认证的图像?
- c# - 将大型 .txt 文件与值数组进行比较
- r - 依赖于两个文件的编程函数
- java - 无法使用 Java 进程的 gdb 核心反汇编 $PC
- istio - 设置 istio 1.2.1 时,许多指标都是空的 - 我做错了什么?
- android - Android Studio 启用离线模式不起作用
- autodesk - 设计自动化 API 无法打开 zip 文件
- python - 排序-TypeError:'int'和'str'的实例之间不支持'<',Python
- excel - 如何从带有标题的记录集中复制?
- arrays - PowerShell 3.0 -iin 运算符支持通配符吗?如何以类似的方式使用 -ilike?