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

5.2.3 Release #199

Merged
merged 7 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ artifacts:
deploy:
- provider: NuGet
api_key:
secure: cOwNnD1CeLHceEpQiS89arAbxzPLgQKnsffzu2KthmbTY6OL7rMXrkud6EBq4sOo
secure: TvgNpWJrz95fIzB0+OHqDpzjVgN1BYY9ogCPmYdpmXs3Q7yuya3sz0TQc9UlvJrk
skip_symbols: true
on:
branch: /^(main|dev)$/
Expand Down
2 changes: 1 addition & 1 deletion src/Serilog.Sinks.Seq/SeqLoggerConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion src/Serilog.Sinks.Seq/Serilog.Sinks.Seq.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
22 changes: 19 additions & 3 deletions src/Serilog.Sinks.Seq/Sinks/Seq/ConstrainedBufferedFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
}
}
14 changes: 14 additions & 0 deletions test/Serilog.Sinks.Seq.Tests/ConstrainedBufferedFormatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}