0

I am trying to read through the Windows Event log "Error" entry messages in in c#.

  foreach (EventLogEntry log in eventLog.Entries)
  {
    if (log.EntryType.ToString() == "Error") 
    {
        Console.WriteLine( log.Message);
    }
  }

The output is "The XYZ service failed to start due to the following error: \r\n%%2"

while the entry I am looking for is

"The XYZ service failed to start due to the following error:\r\nThe system cannot find the file specified."

How does one translate from the id to the appropriate error message ?

Many thanks, KG

4

1 回答 1

0

事件日志消息是模板,例如:

The %1 service failed to start due to the following error: \r\n%2

一个事件日志条目包含一个消息号和替换字符串以替代 %1、%2 等。

.NetEventLogEntry.Message属性会为您进行替换,因此您永远不会看到 %1、%2 等。

看起来替换失败了,可能是因为没有足够的替换字符串(检查EventLogEntry.ReplacementStrings属性)或格式字符串格式错误(它似乎有一个杂散的 '%')。尽管如果日志条目来自服务控制管理器,这些解释似乎都不合理。

于 2012-09-21T10:43:11.183 回答