dotnet-api-docs icon indicating copy to clipboard operation
dotnet-api-docs copied to clipboard

Update the maximum message length in the EventLog.WriteEntry method documentation

Open 0xced opened this issue 1 year ago • 4 comments

Summary

It was found empirically on Windows 10 that the maximum message length is 31,718.

0xced avatar Jun 06 '24 13:06 0xced

Tagging subscribers to this area: @tommcdon

Learn Build status updates of commit a78d259:

:white_check_mark: Validation status: passed

File Status Preview URL Details
xml/System.Diagnostics/EventLog.xml :white_check_mark:Succeeded View

For more details, please refer to the build report.

For any questions, please:

@tommcdon Could you review?

gewarren avatar Aug 29 '24 00:08 gewarren

.NET is using ReportEvent, and according to the Windows documentation for ReportEvent, our existing documentation is correct:

https://learn.microsoft.com/windows/win32/api/winbase/nf-winbase-reporteventw

[in] lpStrings
A pointer to a buffer containing an array of null-terminated strings that are merged into the message before Event Viewer displays the string to the user. This parameter must be a valid pointer (or NULL), even if wNumStrings is zero. Each string is limited to 31,839 characters.
Prior to Windows Vista:  Each string is limited to 32K characters.

The .NET code that calls ReportEvent is checking 32K-2 characters:

https://github.com/dotnet/runtime/blob/c1a9f26efa4fcf2e3fdcd8557da19d358f51eb00/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogInternal.cs#L1354-L1357

                // make sure the strings aren't too long.  MSDN says each string has a limit of 32k (32768) characters, but
                // experimentation shows that it doesn't like anything larger than 32766
                if (strings[i].Length > 32766)
                    throw new ArgumentException(SR.LogEntryTooLong);

Therefore, the error would likely be coming from Windows and not .NET for string lengths <= 32766 characters. Given that .NET has no control over the version of Windows and the various character limits it is imposing, I suggest we remove mentions of specific character limits under 32766 characters.

Also I would expect that if the string length is <= 32766 and the API call fails due to a restriction from Windows, we would get a Win32Exception and not an ArgumentException. @0xced can you confirm?

If yes, then I suggest changing the text to something like: The message string is longer than 32,766 bytes.

tommcdon avatar Aug 29 '24 02:08 tommcdon

@0xced Do you plan to address the requested changes?

gewarren avatar Apr 03 '25 20:04 gewarren