Migrate data handling from Serilog's LogEvent across to System.Text.Json.JsonObject, with the help of Seq.Syntax v2.0 - #496
Merged
Conversation
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
…eviously used for trace formatting
nblumhardt-ro
commented
Sep 1, 2026
| @@ -1,31 +1,41 @@ | |||
| using System; | |||
| using System; | |||
Author
There was a problem hiding this comment.
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.
…ould point us in the right direction
nblumhardt-ro
commented
Sep 1, 2026
|
|
||
| namespace SeqCli.Data; | ||
|
|
||
| static class EventJsonDocument |
Author
There was a problem hiding this comment.
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
marked this pull request as draft
September 1, 2026 21:17
Author
|
Blocking on datalust/seq-syntax#7 |
added 4 commits
September 2, 2026 07:19
Assisted-by: Claude:claude-fable-5-1
nblumhardt-ro
marked this pull request as ready for review
September 2, 2026 01:33
Author
|
All good to go! |
KodrAus
reviewed
Sep 2, 2026
| public void Enrich(JsonObject eventJson) | ||
| { | ||
| logEvent.RemovePropertyIfPresent("@i"); | ||
| eventJson["@l"] = level; |
KodrAus
reviewed
Sep 2, 2026
| throw new InvalidDataException($"The line is not a JSON object: `{json.Trim()}`."); | ||
|
|
||
| if (!eventJson.ContainsKey("@t")) | ||
| eventJson["@t"] = DateTime.UtcNow.ToString("O", CultureInfo.InvariantCulture); |
KodrAus
reviewed
Sep 2, 2026
| catch (Exception ex) | ||
| { | ||
| if (ex is JsonReaderException || ex is InvalidDataException) | ||
| if (ex is System.Text.Json.JsonException || ex is InvalidDataException) |
Member
There was a problem hiding this comment.
nit: Does this need to be fully qualified?
KodrAus
reviewed
Sep 2, 2026
| readonly struct ReadResult | ||
| { | ||
| public LogEvent? LogEvent { get; } | ||
| /// <summary> |
KodrAus
reviewed
Sep 2, 2026
| using SeqCli.Data; | ||
| using SeqCli.Output; | ||
|
|
||
| namespace SeqCli.Mapping; |
KodrAus
reviewed
Sep 2, 2026
|
|
||
| if (evt.Elapsed is { } elapsed) | ||
| properties.Add(new(ElapsedProperty, new ScalarValue(elapsed))); | ||
| eventJson[ElapsedProperty] = elapsed.ToString("c", CultureInfo.InvariantCulture); |
KodrAus
reviewed
Sep 2, 2026
| [Fact] | ||
| public void LiteralBracesAreEscapedInTemplateText() | ||
| { | ||
| var (message, _) = StructuredMessage.Read(new JArray("a {not-a-hole} b")); |
Member
There was a problem hiding this comment.
This is actually returning a template
KodrAus
approved these changes
Sep 2, 2026
KodrAus
reviewed
Sep 2, 2026
| try | ||
| { | ||
| var error = JsonConvert.DeserializeObject<dynamic>(resultJson)!; | ||
| var error = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(resultJson)!; |
Member
There was a problem hiding this comment.
Does this need to be Newtonsoft.Json?
KodrAus
approved these changes
Sep 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This one's been in the pipeline for a long time!
seqclioriginally 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
LogEventdata 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 --jsonoutput to (correctly) preserve original, non-Serilog level names in this version (yet one more place where the Serilog model unnecessarily leaked in).