读取EventLog C#错误 [英] Reading EventLog C# Errors
问题描述
我在用C#编写的ASP.NET应用程序中有此代码,该代码试图读取事件日志,但它返回错误.
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;
}
它返回的条目之一是找不到源'tvNZB'中事件ID'0'的描述.本地计算机可能没有必要的注册表信息或消息DLL文件来显示消息,或者您可能没有访问权限.事件中包含以下信息:服务已成功启动."
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?
推荐答案
尝试一下:)
EventLog aLog = new EventLog();
aLog.Log = "Application";
aLog.MachineName = "."; // Local machine
string message = "\'Service started\'";
foreach (EventLogEntry entry in aLog.Entries)
{
if (entry.Source.Equals("tvNZB")
&& entry.EntryType == EventLogEntryType.Information)
{
if (entry.Message.EndsWith(message))
{
Console.Out.WriteLine("> " + entry.Message);
//do stuff
}
}
}
它适用于Win XP home.该消息在另一个操作系统上可能有所不同.
最佳方法:用System.Diagnostics.Trace.Write
转储entry.Message
并查看确切的消息.
It works on Win XP home. The message might be different on another OS.
Best way: dump entry.Message
by System.Diagnostics.Trace.Write
and see the exact message.
希望它工作顺利:)
这篇关于读取EventLog C#错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!