C# 如何导出Windows系统和应用程序事件日志?
使用,我当前无法为C# 如何导出Windows系统和应用程序事件日志?,c#,.net,windows,event-log,C#,.net,Windows,Event Log,使用,我当前无法为路径和/或查询参数指定正确的值 我的目标是导出本地应用程序和系统事件日志 我试过: EvtExportLog( IntPtr.Zero, "Application", "*", "C:\\SomePath\\Application.evtx", EventExportLogFlags.LogFilePath); 使用以下p/Invoke定义: [Flags] private enum EventExportLogFlags {
路径
和/或查询
参数指定正确的值
我的目标是导出本地应用程序和系统事件日志
我试过:
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()
我的问题:
在
路径
和查询
参数中放置什么以导出本地应用程序和系统事件日志?回答我自己的问题:
我的路径
和查询
实际上是正确的。问题在于标志
参数
我没有指定EventExportLogFlags.LogFilePath
参数,而是必须指定EventExportLogFlags.ChannelPath
参数
然后导出成功:
EvtExportLog(
IntPtr.Zero,
"Application",
"*",
"C:\\SomePath\\Application.evtx",
EventExportLogFlags.ChannelPath); // <-- HERE!
EvtExportLog(
IntPtr.Zero,
“应用程序”,
"*",
“C:\\SomePath\\Application.evtx”,
EventExportLogFlags.ChannelPath)//