【问题标题】:How to export Windows System and Application event log?如何导出 Windows 系统和应用程序事件日志?
【发布时间】:2015-05-27 09:14:59
【问题描述】:

使用EvtExportLog function,我目前无法为Path 和/或Query 参数指定正确的值。

我的目标是导出本地 ApplicationSystem 事件日志。

我试过了:

EvtExportLog(
    IntPtr.Zero, 
    "Application", 
    "*", 
    "C:\\SomePath\\Application.evtx", 
    EventExportLogFlags.LogFilePath);

使用以下 P/Invoke 定义:

[Flags]
private enum EventExportLogFlags
{
    ChannelPath = 1,
    LogFilePath = 2,
    TolerateQueryErrors = 0x1000
};

[DllImport(@"wevtapi.dll", 
    CallingConvention = CallingConvention.Winapi,
    CharSet = CharSet.Auto,
    SetLastError = true)]
private static extern bool EvtExportLog(
    IntPtr sessionHandle,
    string path,
    string query,
    string targetPath,
    [MarshalAs(UnmanagedType.I4)] EventExportLogFlags flags);

不幸的是,该函数返回 false 和最后一个错误代码 2 (ERROR_FILE_NOT_FOUND)。

我的问题:

PathQuery 参数中添加什么来导出本地应用程序和系统事件日志?

【问题讨论】:

    标签: c# .net windows event-log


    【解决方案1】:

    回答我自己的问题:

    我的PathQuery 实际上是正确的。出了什么问题,是 Flags 参数。

    我必须指定EventExportLogFlags.ChannelPath 参数,而不是指定EventExportLogFlags.LogFilePath 参数。

    那么导出成功:

    EvtExportLog(
        IntPtr.Zero, 
        "Application", 
        "*", 
        "C:\\SomePath\\Application.evtx", 
        EventExportLogFlags.ChannelPath); // <-- HERE!
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-24
      • 2014-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多