Skip to content

Commit

Permalink
Attempt to mitigate allocations in structured rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Nickztar committed Jan 15, 2024
1 parent 2f48591 commit 2d8734c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions Serilog.Sinks.LogtailSys/Formatters/LogtailFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,10 @@ private string GetMessageId(LogEvent logEvent)

private string RenderStructuredData(LogEvent logEvent)
{
var properties = logEvent.Properties.Select(kvp =>
new KeyValuePair<string, string>(RenderPropertyKey(kvp.Key), RenderPropertyValue(kvp.Value)));
var tokenPart = $"{tokenKey}=\"{token}\"";
var structuredDataKvps = string.Join(" ", properties.Select(t => $"""
{t.Key}="{t.Value}"
"""));
var structuredDataKvps = string.Join(" ", logEvent.Properties.Select(t => $"""
{RenderPropertyKey(t.Key)}="{RenderPropertyValue(t.Value)}"
"""));
var structuredData = string.IsNullOrEmpty(structuredDataKvps) ? $"[{tokenPart}]" : $"[{tokenPart}][{dataName} {structuredDataKvps}]";

return structuredData;
Expand Down
2 changes: 1 addition & 1 deletion Serilog.Sinks.LogtailSys/Serilog.Sinks.LogtailSys.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Description>Fully-featured Serilog sink that logs events to logtail using UDP (rSyslog).</Description>
<Authors>Nicholas Brostrom (Nickztar)</Authors>
<Company>Effectsoft AB</Company>
<VersionPrefix>1.0.4</VersionPrefix>
<VersionPrefix>1.0.5</VersionPrefix>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down

0 comments on commit 2d8734c

Please sign in to comment.