读取 EventLog C# 错误
我的 ASP.NET 应用程序中有一段用 C# 编写的代码,它试图读取事件日志,但它返回一个错误。
EventLog aLog = new EventLog();
aLog.Log = "Application";
aLog.MachineName = "."; // Local machine
foreach (EventLogEntry entry in aLog.Entries)
{
if (entry.Source.Equals("tvNZB"))
Label_log.Text += "<p>" + entry.Message;
}
它返回的条目之一是“无法找到源“tvNZB”中事件 ID“0”的描述。本地计算机可能没有必要的注册表信息或消息 DLL 文件来显示该消息,或者您可能没有权限访问它们。以下信息是事件的一部分:“服务已成功启动。”
我只想要“服务已成功启动”。有什么想法吗?
I have this code in my ASP.NET application written in C# that is trying to read the eventlog, but it returns an error.
EventLog aLog = new EventLog();
aLog.Log = "Application";
aLog.MachineName = "."; // Local machine
foreach (EventLogEntry entry in aLog.Entries)
{
if (entry.Source.Equals("tvNZB"))
Label_log.Text += "<p>" + entry.Message;
}
One of the entries it returns is "The description for Event ID '0' in Source 'tvNZB' cannot be found. The local computer may not have the necessary registry information or message DLL files to display the message, or you may not have permission to access them. The following information is part of the event:'Service started successfully.'"
I only want the 'Service started successfully'. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:)
它适用于 Win XP 家庭版。该消息在另一个操作系统上可能有所不同。
最好的方法:通过 System.Diagnostics.Trace.Write 转储
entry.Message
并查看确切的消息。希望一切顺利:)
Try this :)
It works on Win XP home. The message might be different on another OS.
Best way: dump
entry.Message
bySystem.Diagnostics.Trace.Write
and see the exact message.Hope it works smoothly :)