From 4fdca690b5b18bb3ce3828f91d37aa1e1265d5ab Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Tue, 15 Nov 2022 12:02:42 +1000 Subject: [PATCH 1/5] Dev version bump [skip ci] --- src/Serilog.Sinks.Seq/Serilog.Sinks.Seq.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 @@ Serilog sink that writes to the Seq log server over HTTP/HTTPS. - 5.2.2 + 5.2.3 Serilog Contributors Copyright © Serilog Contributors net5.0;netstandard1.1;netstandard1.3;netstandard2.0;net4.5;netcoreapp3.1 From 3e60b2248fadfe257eb0fdd86c7a171a43e69a77 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Tue, 15 Nov 2022 12:03:01 +1000 Subject: [PATCH 2/5] Publishing key update --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)$/ From 3fc786b08f8d4fd9e0010f52b6b53261bb5cccbb Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Tue, 22 Nov 2022 10:02:05 +1000 Subject: [PATCH 3/5] Include a large event body sample when generating oversized event placeholders --- .../Sinks/Seq/ConstrainedBufferedFormatter.cs | 22 ++++++++++++++++--- .../ConstrainedBufferedFormatterTests.cs | 14 ++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) 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..f6fc66e 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, 3976)] + public void PlaceholderSampleSizeIsComputedFromEventBodyLimitBytes(long eventBodyLimitBytes, long expectedSampleSize) + { + var actual = ConstrainedBufferedFormatter.GetOversizeEventSampleLength(eventBodyLimitBytes); + Assert.Equal(expectedSampleSize, actual); + } } } From 34a274fbb2116f5a4844fdc01b177f6d8d259262 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Tue, 22 Nov 2022 10:23:00 +1000 Subject: [PATCH 4/5] Missing commit --- .../ConstrainedBufferedFormatterTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Serilog.Sinks.Seq.Tests/ConstrainedBufferedFormatterTests.cs b/test/Serilog.Sinks.Seq.Tests/ConstrainedBufferedFormatterTests.cs index f6fc66e..dcf7acb 100644 --- a/test/Serilog.Sinks.Seq.Tests/ConstrainedBufferedFormatterTests.cs +++ b/test/Serilog.Sinks.Seq.Tests/ConstrainedBufferedFormatterTests.cs @@ -48,7 +48,7 @@ public void PlaceholdersAreLoggedWhenTheEventSizeLimitIsExceeded() [InlineData(1000, 512)] [InlineData(5000, 1476)] [InlineData(10000, 3976)] - [InlineData(130048, 3976)] + [InlineData(130048, 64000)] public void PlaceholderSampleSizeIsComputedFromEventBodyLimitBytes(long eventBodyLimitBytes, long expectedSampleSize) { var actual = ConstrainedBufferedFormatter.GetOversizeEventSampleLength(eventBodyLimitBytes); From acc44085222567ed4a91948c1f1859df9d5aff5b Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Fri, 3 Feb 2023 16:02:39 +1000 Subject: [PATCH 5/5] Avoid using an obsolete source-compatible overload of WriteTo.Sink() that may be removed in Serilog 3. See https://github.com/serilog/serilog/issues/1843 --- src/Serilog.Sinks.Seq/SeqLoggerConfigurationExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)); } ///