簡體   English   中英

獲取Windows事件日志文件的位置

[英]Get the location of windows event log files

我們使用EventLog來記錄異常。 有一個后台線程,一旦事件日志滿了就檢查,programmaticaly將條目傳輸到XML文件,然后清除事件日志。

這工作正常,但似乎有太多的工作要完成,我認為最好簡單地復制用於記錄當前應用程序的.evt文件,然后清除事件日志。

有沒有辦法找到適用於每個Windows操作系統的文件的位置/路徑?

建議使用

Registry.LocalMachine.OpenSubKey("System\\CurrentControlSet\\Services\\EventLog\\" + e.Log);

但后來我的應用程序日志名稱沒有File屬性。

你現在如何存檔? 也許可以改進該方法以獲得性能。

這是一個例子。

EventLogSession els = new EventLogSession();
els.ExportLogAndMessages("Security",             // Log Name to archive
                         PathType.LogName,       // Type of Log
                         "*",                    // Query selecting all events
                         "C:\\archivedLog.evtx", // Exported Log Path 
                         false,                  // Stop archive if query is invalid
                         CultureInfo.CurrentCulture);

或者您可以使用ClearLog()方法。

EventLogSession els = new EventLogSession();

// Clears all the events and archives them to the .evtx file
els.ClearLog("System",          //  Channel to Clear
             "c:\\myLog.evtx"); //  Backup File Path

更多信息可以在這里找到:

導出,存檔和清除事件日志

暫無
暫無

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

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