6

when i write log to windows eventlog:

System.Diagnostics.EventLog.WriteEntry("SourceName", a_long_string);

i got the following exception:

Log entry string is too long. A string written to the event log cannot exceed 32766 characters.

then i splits my log message into 2 or more string. but i don't think it is a good idea. any workarounds? (such as extern the limit per log entry)

2
  • 2
    I would question the usability of a system that requires writing entries this long to the eventlog.
    – Joe
    Commented Oct 10, 2011 at 17:29
  • To make things even more confusing, the msdn article on event logging api claims that on post-vista computers the limit is in fact 31839 Thus .net check for 32766 and corresponding ArgumentException is incorrect.
    – durilka
    Commented May 28, 2013 at 8:33

1 Answer 1

20

The Event Log isn't intended for storing Chapter 1 of War and Peace. You really should reconsider what you're writing to the event log.

If you want to log something voluminous (e.g. a crash dump), you can always store it somewhere on disk and write a message to the EventLog something like Generated dump at C:\Users\MyUserName\AppData\Local\MyApp\WarAndPeace.pdf.

1
  • 5
    I may be the minority but, I am not fond of a diagnostics component used to record errors effectively masking the actual reason for logging a potential fault. If War and Peace is not possible then truncate the message with an indication of the message modification. I don't disagree that the messages should be constrained and/or logged using a different medium. This exception forces everyone who has ever written a trace in your application including 3rd parties to constrain the string using the default event log listener.Bug? Commented Jul 3, 2013 at 1:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.