1

我用谷歌搜索了很多可能的答案,但没有运气。我正在尝试从事件日志(伪代码)中提取以下内容:

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() + "]]" +
")" +
");"

我是否试图创建一个对于事件日志查询评估器来说太难的表达式,或者我只是在表达式中有一个简单的错误?我一直在尝试各种形式的表达。似乎“级别”过滤器只是被忽略了,但为什么呢?

4

2 回答 2

2

*** 啊!!- 我想我找到了。事件日志级别枚举为:

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)))]]
于 2018-07-30T19:59:03.503 回答
0

我可以在您发布的代码中看到两个问题。

  • 单引号未在第 3 个名称上关闭:@Name='<3rd name>]]应该是@Name='<3rd name>']]
  • 第二个过滤器*/System/Level应该是*[System[Level<=" + maxLevel.ToString() + "]]] "

从您的伪代码和您共享的内容来看,您似乎可以在谓词过滤器中合并和移动一些逻辑,*/System并使用 XPath,例如:

string queryString = 
"*[System[TimeCreated[@SystemTime>='" + dFrom + "' and @SystemTime<='" + dTo + "']" +
"  and (Level<=2 or " +
"    (Provider[@Name='<1st name>' or @Name='<2nd name>' or @Name='<3rd name>'] " + 
"     and Level<=" + maxLevel.ToString() + "))" + 
"]];"
于 2018-07-30T01:32:16.430 回答