你如何编程方式打开事件日志? [英] How do you open the event log programatically?

查看:135
本文介绍了你如何编程方式打开事件日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用错误记录到事件日志中常用的:

I'm logging errors to the event log using the usual:

 System.Diagnostics.Trace.TraceError("<" + purpose + "><time>" + DateTime.Now.ToUniversalTime() + "</time><message>" + message + "</message></" + purpose + ">");

和我想知道如果有一种方法来调用这个日志文件,并显示其用户(无论是在我自己的格式,或直接打开一样事件查看器的事件日志文件)。

and am wondering if there is a way to call this log file and display it for the user (either in my own format or by opening the event log file directly as does 'Event Viewer').

我发现位于%SystemRoot文件%\ SYSTEM32 \ Winevt \日志\ mylog.evtx,但不知道我是否应该接近这种方式与否。理想情况下,我想效仿事件查看器,但定制我的应用程序。

I've found the file in %SystemRoot%\System32\Winevt\Logs\mylog.evtx but not sure whether I should be approaching it this way or not. Ideally I'd like to emulate what the Event Viewer does but customised for my application.

推荐答案

尝试的 System.Diagnostics.EventLog

例如,你可以在应用程序中查看日志条目如下:

For Example, you can view entries in the applications log as follows

var log = EventLog.GetEventLogs().Where(x => x == "Application").First();
foreach (var entry in log.Entries) {
  // Do something with the entry
}

这篇关于你如何编程方式打开事件日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆