【问题标题】:How can I query the event log for a specific source using xpath?如何使用 xpath 查询特定源的事件日志?
【发布时间】:2013-12-23 12:53:04
【问题描述】:

我想在整个 Windows 事件日志(例如应用程序)中查询由特定源(例如 MSSQL$SQLEXPRESS)写入的事件。我已经编写了工作代码来搜索事件 ID:

string xpathQuery = string.Format("*[System/EventID={0}]", intFilter);
EventLogQuery query = new EventLogQuery(eventLogName, PathType.LogName, xpathQuery);
EventLogReader reader = new EventLogReader(query);
for (EventRecord eventInstance = reader.ReadEvent(); null != eventInstance; eventInstance = reader.ReadEvent())
{
    lisRecords.Add(eventInstance);
}

我必须如何更改 xpathQuery,才能搜索 4 个 eventlog-entry-sources?

【问题讨论】:

    标签: c# windows xpath event-log


    【解决方案1】:

    像这样更改查询字符串(您可能希望创建一个文本资源并将此查询放入其中以避免转义):

    *[System[Provider[@Name='Microsoft-Windows-ADSI' or @Name='Outlook'] and (EventID=1 or EventID=2 or EventID=3)]]
    

    以上等价于:

    (EventID in (1,2,3)) and (Source in ('Microsoft-Windows-ADSI', 'Outlook'))
    

    【讨论】:

    • 但是如何为过滤器正确转义创建的时间? *[[System/Provider/@Name=\"MySource\"] and TimeCreated[timediff(@SystemTime) & lt;= 2592000000]]]
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-25
    • 2011-07-12
    • 2010-09-08
    • 2013-03-06
    • 1970-01-01
    相关资源
    最近更新 更多