繁体   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