簡體   English   中英

System.Diagnostics.Eventing.Reader.EventLogException:目錄名稱無效

[英]System.Diagnostics.Eventing.Reader.EventLogException: The directory name is invalid

我正在嘗試使用以下命令導出事件日志

private static void ExportEventLogs(string exportPath, string Log)
    {
        var ela = new EventLogSession();
        try
        {
            ela.ExportLogAndMessages(Log, PathType.LogName, "*", exportPath + ".evtx", false, CultureInfo.CurrentCulture);
            // weird error direcoty invalid ?????
        }
        catch (EventLogException e)
        {
            //System.Windows.MessageBox.Show(e.ToString());
            Clipboard.SetDataObject(e.ToString());
        }

    }

並在此處調用它,它應該從當前用戶配置文件上的計算機名稱創建一個目錄,並將計算機名+日志名添加到該目錄中

 ExportEventLogs(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Desktop\\" + System.Environment.MachineName + "\\" + System.Environment.MachineName, "Application");

我遇到的問題是“導演姓名”無效,但它創建了正確的文件,有關為什么的任何想法? 我也嘗試過以管理員身份運行代碼,結果相同

 System.Diagnostics.Eventing.Reader.EventLogException: The directory name is invalid
 at System.Diagnostics.Eventing.Reader.EventLogException.Throw(Int32 errorCode)
 at         System.Diagnostics.Eventing.Reader.NativeWrapper.EvtArchiveExportedLog(EventLogHandle session, String logFilePath, Int32 locale, Int32 flags)
 at System.Diagnostics.Eventing.Reader.EventLogSession.ExportLogAndMessages(String path,  PathType pathType, String query, String targetFilePath, Boolean tolerateQueryErrors, CultureInfo targetCultureInfo)
 at Log_Utility.MainWindow.ExportEventLogs(String exportPath, String Log) in c:\Users\Chris.Ondrovic\Documents\Visual Studio 2013\Projects\Log Utility\Log Utility\MainWindow.xaml.cs:line 156

對於那些看着這個但仍然無法弄清楚發生此錯誤的情況的人-我找到了解決方案。

在嘗試導出應用程序系統日志時看到此錯誤之后,我決定以Admin身份運行VS,並看到在指定的同一路徑下正在與文件一起創建LocaleMetaData文件夾。 這是它試圖將信息保存到的文件夾,並且根據您要保存的位置,您可能需要管理員權限。

不幸的是,異常消息無法告訴您正在發生的事情,因為當我看到正在創建文件但仍然遇到異常時,我正在抓撓自己。

復制您的代碼並將其粘貼到新程序中,沒有得到無效的目錄名稱。 我確實必須確保在導出之前該目錄存在。 我的建議是查看exportPath並確保它不包含任何無效字符。

代替“ PathType.LogName”,使用“ PathType.FilePath” LogName用於指定日志的名稱,例如“ Application”或“ Security”

在我看來正在傳遞文件路徑

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM