C# 导出事件日志时出现异常
我使用fallowing代码导出Windows事件日志:C# 导出事件日志时出现异常,c#,.net,event-log,C#,.net,Event Log,我使用fallowing代码导出Windows事件日志: var els = new EventLogSession(); els.ExportLogAndMessages("Application", PathType.LogName, "*[System[Provider[@Name='Prayon.Client']]]",
var els = new EventLogSession();
els.ExportLogAndMessages("Application",
PathType.LogName,
"*[System[Provider[@Name='Prayon.Client']]]",
tempEventLogPath,
false,
CultureInfo.CurrentCulture);
这通常是有效的。但在一台机器上,我得到了一个例外:
System.Diagnostics.Eventing.Reader.EventLogException: Der Verzeichnisname ist ungültig
bei System.Diagnostics.Eventing.Reader.EventLogException.Throw(Int32 errorCode)
bei System.Diagnostics.Eventing.Reader.NativeWrapper.EvtArchiveExportedLog(EventLogHandle session, String logFilePath, Int32 locale, Int32 flags)
bei System.Diagnostics.Eventing.Reader.EventLogSession.ExportLogAndMessages(String path, PathType pathType, String query, String targetFilePath, Boolean tolerateQueryErrors, CultureInfo targetCultureInfo)
“Der Verzeichnisname ist ungültig”
在英语中的意思是:“路径名无效”
应用程序事件日志已存在,tempEventLogPath
也有效
有人知道会有什么问题吗?请参阅以下内容中的可能答案:
问题是,即使您有权访问答案中提到的目录,也可能由于UAC通知而失败(您可以禁用UAC,它应该可以工作)。尝试删除目标目录中的目录LocalMetaData 我也有同样的问题。 第一个调用可以工作,但后面的每个调用都会得到上述异常。 Processmonitor的调查显示,除了evtx文件之外,还可以访问LocalMetaData目录。
删除此目录后,导出将再次工作。tempEventLogPath的值是多少?