From 5fe6686e9025568105b2a71758f0c504586fdbbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Luthi?= Date: Thu, 6 Jun 2024 15:20:22 +0200 Subject: [PATCH] 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 --- src/Serilog.Sinks.EventLog/Sinks/EventLog/EventLogSink.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Serilog.Sinks.EventLog/Sinks/EventLog/EventLogSink.cs b/src/Serilog.Sinks.EventLog/Sinks/EventLog/EventLogSink.cs index efaa4c7..8b486e5 100644 --- a/src/Serilog.Sinks.EventLog/Sinks/EventLog/EventLogSink.cs +++ b/src/Serilog.Sinks.EventLog/Sinks/EventLog/EventLogSink.cs @@ -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);