带有.net 4.5的EventLog WriteEntry()argumentException错误

时间:2014-01-08 13:08:44

标签: c# .net event-log argumentexception

因为我已将我的代码迁移到.net 4.5,所以当我尝试使用eventID>编写eventLog时出错。 65535

这是我的代码,其中iID是> 65535:

 System.Diagnostics.EventLog appLog = new System.Diagnostics.EventLog();
 appLog.Source = "my source";
 appLog.WriteEntry(sMsg, EventLogEntryType.Error, iID);

根据定义,eventID很好是一个int32所以我不明白为什么我会在那里得到错误。

这里是堆栈跟踪:

   at System.Diagnostics.EventLogInternal.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
   at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID)
   at WSeProcFilesHandler.EventLog_AddEntry(String sMsg, Int32 iID) in d:\Liox\TFS\Eprocurement\Main\Dev\Eprocurement\Services\WAeProcFilesHandler\WSeProcFilesHandler.cs:line 567

欢迎任何帮助。 感谢

1 个答案:

答案 0 :(得分:0)

嗯,msdn

中说明了这一点
  

ArgumentException

     
      
  • 或 - eventID小于零或大于UInt16.MaxValue。
  •   

没有解释为什么Int32参数仅限于UInt16,说实话......

管理此方法的一种方法是使用事件日志类别(请参阅此overload)。因此,每个类别可能有65536个ID。

顺便说一下,那是很多不同的事件日志ID,不是吗?