diff --git a/appveyor.yml b/appveyor.yml index 06c37b8..ffa60c1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -17,7 +17,7 @@ artifacts: deploy: - provider: NuGet api_key: - secure: cOwNnD1CeLHceEpQiS89arAbxzPLgQKnsffzu2KthmbTY6OL7rMXrkud6EBq4sOo + secure: TvgNpWJrz95fIzB0+OHqDpzjVgN1BYY9ogCPmYdpmXs3Q7yuya3sz0TQc9UlvJrk skip_symbols: true on: branch: /^(main|dev)$/ diff --git a/src/Serilog.Sinks.Seq/SeqLoggerConfigurationExtensions.cs b/src/Serilog.Sinks.Seq/SeqLoggerConfigurationExtensions.cs index 9536abf..528659c 100644 --- a/src/Serilog.Sinks.Seq/SeqLoggerConfigurationExtensions.cs +++ b/src/Serilog.Sinks.Seq/SeqLoggerConfigurationExtensions.cs @@ -134,7 +134,7 @@ public static LoggerConfiguration Seq( return loggerSinkConfiguration.Conditional( controlledSwitch.IsIncluded, - wt => wt.Sink(sink, restrictedToMinimumLevel)); + wt => wt.Sink(sink, restrictedToMinimumLevel, levelSwitch: null)); } /// <summary> diff --git a/src/Serilog.Sinks.Seq/Serilog.Sinks.Seq.csproj b/src/Serilog.Sinks.Seq/Serilog.Sinks.Seq.csproj index a102488..646f74b 100644 --- a/src/Serilog.Sinks.Seq/Serilog.Sinks.Seq.csproj +++ b/src/Serilog.Sinks.Seq/Serilog.Sinks.Seq.csproj @@ -2,7 +2,7 @@ <PropertyGroup> <Description>Serilog sink that writes to the Seq log server over HTTP/HTTPS.</Description> - <VersionPrefix>5.2.2</VersionPrefix> + <VersionPrefix>5.2.3</VersionPrefix> <Authors>Serilog Contributors</Authors> <Copyright>Copyright © Serilog Contributors</Copyright> <TargetFrameworks>net5.0;netstandard1.1;netstandard1.3;netstandard2.0;net4.5;netcoreapp3.1</TargetFrameworks> diff --git a/src/Serilog.Sinks.Seq/Sinks/Seq/ConstrainedBufferedFormatter.cs b/src/Serilog.Sinks.Seq/Sinks/Seq/ConstrainedBufferedFormatter.cs index 8268b2c..2a4120d 100644 --- a/src/Serilog.Sinks.Seq/Sinks/Seq/ConstrainedBufferedFormatter.cs +++ b/src/Serilog.Sinks.Seq/Sinks/Seq/ConstrainedBufferedFormatter.cs @@ -107,9 +107,8 @@ static bool CheckEventBodySize(string jsonLine, long? eventBodyLimitBytes) static LogEvent CreateOversizeEventPlaceholder(LogEvent logEvent, string jsonLine, long eventBodyLimitBytes) { - // If the limit is so constrained as to disallow sending 512 bytes + packaging, that's okay - we'll just drop - // the placeholder, too. - var sample = jsonLine.Substring(0, Math.Min(jsonLine.Length, 512)); + var sampleLength = GetOversizeEventSampleLength(eventBodyLimitBytes); + var sample = jsonLine.Substring(0, Math.Min(jsonLine.Length, (int)sampleLength)); return new LogEvent( logEvent.Timestamp, LogEventLevel.Error, @@ -121,5 +120,22 @@ static LogEvent CreateOversizeEventPlaceholder(LogEvent logEvent, string jsonLin new LogEventProperty("EventBodySample", new ScalarValue(sample)), }); } + + internal static long GetOversizeEventSampleLength(long eventBodyLimitBytes) + { + // A quick estimate of how much of the original event payload we should send along with the oversized event + // placeholder. If the limit is so constrained as to disallow sending the sample, that's okay - we'll + // just drop the placeholder, too. + + // In reality the timestamp and other envelope components won't be anything close to this. + const long packagingAllowance = 2048; + var byteBudget = eventBodyLimitBytes - packagingAllowance; + + // Allow for multibyte characters and JSON escape sequences. + var withEncoding = byteBudget / 2; + + const long minimumSampleSize = 512; + return Math.Max(withEncoding, minimumSampleSize); + } } } diff --git a/test/Serilog.Sinks.Seq.Tests/ConstrainedBufferedFormatterTests.cs b/test/Serilog.Sinks.Seq.Tests/ConstrainedBufferedFormatterTests.cs index 9b1b0e3..dcf7acb 100644 --- a/test/Serilog.Sinks.Seq.Tests/ConstrainedBufferedFormatterTests.cs +++ b/test/Serilog.Sinks.Seq.Tests/ConstrainedBufferedFormatterTests.cs @@ -40,5 +40,19 @@ public void PlaceholdersAreLoggedWhenTheEventSizeLimitIsExceeded() Assert.Contains("\"EventBodySample\"", jsonString); Assert.Contains("aaaaa", jsonString); } + + [Theory] + [InlineData(0, 512)] + [InlineData(1, 512)] + [InlineData(512, 512)] + [InlineData(1000, 512)] + [InlineData(5000, 1476)] + [InlineData(10000, 3976)] + [InlineData(130048, 64000)] + public void PlaceholderSampleSizeIsComputedFromEventBodyLimitBytes(long eventBodyLimitBytes, long expectedSampleSize) + { + var actual = ConstrainedBufferedFormatter.GetOversizeEventSampleLength(eventBodyLimitBytes); + Assert.Equal(expectedSampleSize, actual); + } } }