0

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

1 Answer 1

1

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 ?

Sign up to request clarification or add additional context in comments.

4 Comments

it's what I saw but like you I don't understand why it's limited to UInt16.MaxValue. Is there any way to increase this size ?
I will use a fix eventID and move the iID intto the sMsg string. thanks for your help
@Denfer06 yes, the eventID should be something like a "type of event", not a sort of autoincremental number.
Hi thanks yes I'd followed a tutorial on creating a service and have a method called GetEventId() that was just incrementing. This just caught me out too (weird as this is an x64 app?!). Anyway, as you say, high amount of distinct IDs and I can just assign an ID for each module that calls to write an update to the log.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.