"找不到源Y中事件ID X的描述."

“The description for Event ID X in Source Y cannot be found.”
2021-07-31
  •  译文(汉语)
  •  原文(英语)

我正在尝试将自定义事件从Web应用程序写入Windows事件日志.我没有让消息字符串正常工作的运气,我不断收到"找不到源Y中的事件ID X的描述".

为了缩小范围,我决定将事件写到计算机上已经存在的源中.我只是查看了已经记录的事件之一,特别是SceCli事件1704.

我执行以下代码:

var log = new EventLog("Application");
log.Source = "SceCli";

var ev = new EventInstance(1704, 0, EventLogEntryType.Information);
log.WriteEvent(ev);

但是,这仍然在事件查看器中为我提供了以下内容:

找不到源(SceCli)中事件ID(1704)的描述.本地计算机可能没有必要的注册表信息或消息DLL文件来显示来自远程计算机的消息.您可能可以使用/ AUXSOURCE =标志来检索此描述.有关详细信息,请参见"帮助和支持".以下信息是事件的一部分:事件日志文件已损坏.

我不确定我在这里想念的是什么.我正在写出已经存在的完全相同的事件,但仍然找不到消息字符串.

解决过程1

我也面临类似的问题.这样做的大量研究后,根据这篇文章,我没有下面我验证的步骤http://www.codeproject.com/Articles/4166/Using-MC-exe-message-resources-and-the-NT-event-lo一切似乎已经到位.除了一件事..当我偶然发现此msdn http://msdn.microsoft.com/zh-cn/library/windows/desktop/aa363661(v=vs.85).aspx时,我意识到了这一点.

如上一段所述."如果应用程序调用RegisterEventSource并传递在注册表中找不到的源名称,则事件记录服务默认情况下使用应用程序日志.但是,因为没有消息文件,所以事件查看器无法将任何事件标识符或事件类别映射到描述字符串,并且将显示错误.因此,您应该为应用程序的注册表添加唯一的事件源,并指定一个消息文件.因此,RegisterEventSource中的应用程序名称与注册表中的应用程序名称不匹配.我已解决此问题,现在它可以工作了...因此,如果您遇到此问题,请仔细检查注册表项.

速聊1:
出现了我的应用程序通常会安装密钥的问题,然后在我启动它时添加了一个事件日志条目.我启动了我的应用程序,并收到此错误.在安装过程中出现了问题,并且未创建密钥.基本上,这个答案告诉我:"转到注册表,看看您的密钥是否在那里!" 谢谢-发现不是,并且可以从那里继续进行.
解决过程2

您能正确看到其他事件吗?很可能您无法使用该特定的源和事件ID(SceCli / 1704),因为C#事件类没有提供正确数量的参数来匹配事件消息文件中的事件模板.我认为它仅适用于事件消息文件中仅包含"%1"的源(有关此信息,请参阅http://www.eventid.net/show-DocId-22.htm).

无论如何,我认为您需要为自定义应用程序创建一个源(如果不存在),然后记录日志条目.在记录事件之前,请检查源是否存在,如果不存在则创建源:

if (!EventLog.SourceExists("MyWebApp"))
         EventLog.CreateEventSource("MyWebApp", "Application");
EventLog.WriteEntry("MyWebApp", "Some message", EventLogEntryType.Information, 1704);

I'm trying to write custom events from my web application to the windows event log. I've had no luck getting the message strings to work, I keep getting "The description for Event ID X in Source Y cannot be found."

In trying to narrow this down I decided to write out an event to a source that already exists on my machine. I just looked at one of the events that was already written out, specifically SceCli event 1704.

I execute the following code:

var log = new EventLog("Application");
log.Source = "SceCli";

var ev = new EventInstance(1704, 0, EventLogEntryType.Information);
log.WriteEvent(ev);

However, this still gives me the following in Event Viewer:

The description for Event ID ( 1704 ) in Source ( SceCli ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: The event log file is corrupt..

I'm not sure what I'm missing here. I'm writing out the exact same event that already exists, and it still can't find the message string.

Solutions1

I also faced similar problem. After doing lot of research I did following I verified the steps according to this article http://www.codeproject.com/Articles/4166/Using-MC-exe-message-resources-and-the-NT-event-lo Everything seemed to be in place. Except one thing..i realised it when I stumbled on this msdn http://msdn.microsoft.com/en-us/library/windows/desktop/aa363661(v=vs.85).aspx

As last paragraph says.. 'If the application calls RegisterEventSource and passes a source name that cannot be found in the registry, the event-logging service uses the Application log by default. However, because there are no message files, the Event Viewer cannot map any event identifiers or event categories to a description string, and will display an error. For this reason, you should add a unique event source to the registry for your application and specify a message file.' So my application name in RegisterEventSource was not matching with the application name in registry. I fixed this and now it works... So please double check your registry entries if you face this problem.

Talk1:
Had the issue where my application normally installs the key, then adds an Event Log entry when I start it. I started my app and got this error. Something went wrong during the installation and the key didn't get created. Basically this answer told me, "Go to the registry and see if your key is there!" Thanks - found it wasn't and was able to proceed from there.
Solutions2

Can you see the other events properly? Most probably you are unable to use that particular source and event id (SceCli/1704) because the C# event class does not provide the right number of parameters to match the event template in the event message file. I think it will only work with sources that have just "%1" in their event message file (see http://www.eventid.net/show-DocId-22.htm for more details about that).

Anyway, I think you need to create a source for your custom application (if it doesn't exist) and then record the log entry. Before recording an event check if the source exists and create it if it doesn't:

if (!EventLog.SourceExists("MyWebApp"))
         EventLog.CreateEventSource("MyWebApp", "Application");
EventLog.WriteEntry("MyWebApp", "Some message", EventLogEntryType.Information, 1704);
转载于:https://stackoverflow.com/questions/17087983/the-description-for-event-id-x-in-source-y-cannot-be-found

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入