You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows事件日志XPath查询:contains函数为何无法实现模糊匹配?

Windows事件日志XPath查询:contains函数支持问题

我正在编写XPath查询语句,从Windows事件日志中筛选出事件源包含特定字符串的记录。目前有一个精确匹配的版本可以正常运行,对应的Path元素查询语句如下:

Path='Application'>*[System[Provider[@Name='MyApp']

但我需要筛选所有事件源名称包含'MyApp'的事件,查阅资料后尝试使用以下语句:

Path='Application'>*[System[Provider[contains(@Name, 'MyApp']

执行时却提示Invalid Query错误。


更新内容

按照修正建议调整后,完整查询字符串如下:

var Query = @"<QueryList><Query Id='0' Path='Application'>
                        <Select Path='Application'>*[System[Provider[contains(@Name, 'MyApp')] and (Level=2 or Level=3)]]</Select>
                        </Query></QueryList>";

var EventLogQuery = new EventLogQuery("Application", PathType.LogName, Query);

但执行仍然失败。如果将查询改为精确匹配的版本:

var Query = @"<QueryList><Query Id='0' Path='Application'>
                                <Select Path='Application'>*[System[Provider[@Name='MyApp'] and (Level=2 or Level=3)]]</Select>
                                </Query></QueryList>";

则可以正常运行。

请问EventLogQuery是否支持contains函数?有资料显示可能不支持。


内容的提问来源于stack exchange,提问作者Nigel Tunnicliffe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 11:42:35