Skip to content

Conversation

@baliestri
Copy link
Contributor

This pull aim to solve an issue in GrafanaLoki where the sink fails to serialize the LokiBatch object when reflection-based JSON serialization is disabled in .NET 8.0+ (i.e., when JsonSerializerIsReflectionEnabledByDefault is set to false). The problem originates in the LokiBatch.cs file, where JsonSerializer.Serialize lacks proper JsonTypeInfo metadata for reflection-free serialization.

Fixes #297

@mishamyte mishamyte added the bug Something isn't working label Jun 4, 2025
@mishamyte
Copy link
Member

Hi @baliestri,

Thanks for finding and contribution.
I'm wondering would it work correctly without JsonSerializerContext for LokiStream model too?

@baliestri
Copy link
Contributor Author

Thanks for finding and contribution. I'm wondering would it work correctly without JsonSerializerContext for LokiStream model too?

Yeah, if you open the generated code you will see the LokiStream already serialized, it generates for each type inside of the object you said it should serialize. So the LokiStream will receive a JsonTypeInfo too.

@mishamyte mishamyte merged commit a3db1f8 into serilog-contrib:master Jun 4, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Development

Successfully merging this pull request may close these issues.

Sink throws when JsonSerializer Reflection Is Disabled in .NET 8.0

2 participants