当前位置:首页 > 操作系统 > Windows

CodeGo.net>如何导出Windows系统和应用程序事件日志?

如何导出Windows系统和应用程序事件日志?' />

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

我的目标是导出本地应用程序和系统事件日志.

我试过了:

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

具有以下P / Invoke定义:

<code>[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);
</code>

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

我的问题:

要在Path和Query参数中添加什么以导出本地应用程序和系统事件日志?

解决方法:

要回答我自己的问题:

我的路径和查询实际上是正确的.出问题的是Flags参数.

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

然后导出成功:

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

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐