Skip to content

Migrate data handling from Serilog's LogEvent across to System.Text.Json.JsonObject, with the help of Seq.Syntax v2.0 - #496

Merged
KodrAus merged 15 commits into
datalust:devfrom
nblumhardt-ro:seq-syntax-v2
Sep 2, 2026
Merged

Migrate data handling from Serilog's LogEvent across to System.Text.Json.JsonObject, with the help of Seq.Syntax v2.0#496
KodrAus merged 15 commits into
datalust:devfrom
nblumhardt-ro:seq-syntax-v2

Conversation

@nblumhardt-ro

Copy link
Copy Markdown

This one's been in the pipeline for a long time!

seqcli originally piggy-backed on Serilog for event processing and formatting. This made sense when Seq's and Serilog's data models were aligned, but over time, Seq became completely general-purpose and dropped all Serilog-isms in its event model.

As Seq became general purpose only incrementally (first relaxing level name constraints, then adding OTel properties, then dropping existence requirements for things like messages, then adding tracing-specific and metrics-specific schema, ...), the mapping into and out of Serilog's LogEvent data model slowly became contorted and fragile.

This PR moves all event data handling to System.Text.Json.JsonObject, and leans on the v2 preview of Seq.Expressions to reimplement expression evaluation, formatting, and theming. I was able to lean on Claude for the mechanical bits, and I've run over a few more nice-to-have areas just to really strongly avoid any future temptation to mix up our data handling with Serilog.

Externally, the change shouldn't have any obvious behavioral impacts, modulo bugs I'm yet to spot. I did update the trace --json output to (correctly) preserve original, non-Serilog level names in this version (yet one more place where the Serilog model unnecessarily leaked in).

Nicholas Blumhardt added 7 commits September 1, 2026 15:20
…t.Json.JsonObject`, with the help of Seq.Syntax v2.0.

Assisted-by: Claude:claude-fable-5
…t want easy or obvious conversions into Serilog types, the set of scenarios that require this should be and stay vanishingly small
@@ -1,31 +1,41 @@
using System;
using System;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that with this move and a few others, previously-general-purpose types have been scoped back to use only for app hosting interop, or sample data generation.

Comment thread src/SeqCli/Data/EventJsonDocument.cs Outdated

namespace SeqCli.Data;

static class EventJsonDocument

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to pull together more functionality for working with raw JSON events into this namespace; it's a bit bare right now.

@nblumhardt-ro
nblumhardt-ro marked this pull request as draft September 1, 2026 21:17
@nblumhardt-ro

Copy link
Copy Markdown
Author

Blocking on datalust/seq-syntax#7

@nblumhardt-ro
nblumhardt-ro marked this pull request as ready for review September 2, 2026 01:33
@nblumhardt-ro

Copy link
Copy Markdown
Author

All good to go!

public void Enrich(JsonObject eventJson)
{
logEvent.RemovePropertyIfPresent("@i");
eventJson["@l"] = level;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CreateScalar?

Comment thread src/SeqCli/Ingestion/JsonEventReader.cs Outdated
throw new InvalidDataException($"The line is not a JSON object: `{json.Trim()}`.");

if (!eventJson.ContainsKey("@t"))
eventJson["@t"] = DateTime.UtcNow.ToString("O", CultureInfo.InvariantCulture);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CreateScalar?

Comment thread src/SeqCli/Ingestion/LogShipper.cs Outdated
catch (Exception ex)
{
if (ex is JsonReaderException || ex is InvalidDataException)
if (ex is System.Text.Json.JsonException || ex is InvalidDataException)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Does this need to be fully qualified?

Comment thread src/SeqCli/Ingestion/ReadResult.cs Outdated
readonly struct ReadResult
{
public LogEvent? LogEvent { get; }
/// <summary>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: turf

Comment thread src/SeqCli/Mapping/EventEntityJson.cs Outdated
using SeqCli.Data;
using SeqCli.Output;

namespace SeqCli.Mapping;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move into the Api namespace

Comment thread src/SeqCli/Output/TraceFormatter.cs Outdated

if (evt.Elapsed is { } elapsed)
properties.Add(new(ElapsedProperty, new ScalarValue(elapsed)));
eventJson[ElapsedProperty] = elapsed.ToString("c", CultureInfo.InvariantCulture);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CeateScalar

[Fact]
public void LiteralBracesAreEscapedInTemplateText()
{
var (message, _) = StructuredMessage.Read(new JArray("a {not-a-hole} b"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually returning a template

try
{
var error = JsonConvert.DeserializeObject<dynamic>(resultJson)!;
var error = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(resultJson)!;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be Newtonsoft.Json?

@KodrAus
KodrAus merged commit 8730efe into datalust:dev Sep 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants