Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the MaximumPayloadLengthChars #54

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix the MaximumPayloadLengthChars
The [EventLog.WriteEntry documentation][1] says the maximum is 31839 but it was found empirically that the maximum is 31718 on Windows 10.

The `UsingSuperLongLogMessageWorks` test now passes again.

[1]: https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.eventlog.writeentry
  • Loading branch information
0xced committed Jun 6, 2024
commit 5fe6686e9025568105b2a71758f0c504586fdbbe
5 changes: 3 additions & 2 deletions src/Serilog.Sinks.EventLog/Sinks/EventLog/EventLogSink.cs
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ namespace Serilog.Sinks.EventLog
public class EventLogSink : ILogEventSink
{
const string ApplicationLogName = "Application";
const int MaximumPayloadLengthChars = 31839;
const int MaximumPayloadLengthChars = 31_718;
const int MaximumSourceNameLengthChars = 212;
const int SourceMovedEventId = 3;

@@ -65,7 +65,8 @@ public EventLogSink(string source, string logName, ITextFormatter textFormatter,
if (textFormatter == null) throw new ArgumentNullException(nameof(textFormatter));
if (eventIdProvider == null) throw new ArgumentNullException(nameof(eventIdProvider));

// The source is limitted in length and allowed chars, see: https://msdn.microsoft.com/en-us/library/e29k5ebc%28v=vs.110%29.aspx
// The source is limited in length and allowed chars, see: https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.eventlog.writeentry
// This documentation says 31839 bytes is the maximum, but it was found empirically that the maximum is actually 31718 on Windows 10.
if (source.Length > MaximumSourceNameLengthChars)
{
SelfLog.WriteLine("Trimming long event log source name to {0} characters", MaximumSourceNameLengthChars);