문제

since I have migrated my code to .net 4.5, I get errors when I try to write eventLog with eventID > 65535

here is my code where iID is > 65535:

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

based on the definition the eventID is well a int32 so I don't understand why I get error there.

here the stack trace:

   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

any help will be welcomed. thanks

도움이 되었습니까?

해결책

Well, that's stated in msdn

ArgumentException

  • or - eventID is less than zero or greater than UInt16.MaxValue.

No explanation why an Int32 parameter is limited to an UInt16, to be honest...

A way to manage this would be to use eventlogs categories (see this overload). So you might have 65536 ids for each category.

By the way, that's a lot of distinct eventlog ids, no ?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top