Skip to content

Commit a3db1f8

Browse files
authored
Add JsonSerializerContext support (#298)
* Update System.Text.Json package based on TargetFramework * Add and use LokiSerializationContext
1 parent 3f3f006 commit a3db1f8

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/Serilog.Sinks.Grafana.Loki/Models/LokiBatch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ public LokiStream CreateStream()
2828
return stream;
2929
}
3030

31-
public string Serialize() => JsonSerializer.Serialize(this);
31+
public string Serialize() => JsonSerializer.Serialize(this, LokiSerializationContext.Default.LokiBatch);
3232
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2020-2022 Mykhailo Shevchuk & Contributors
2+
//
3+
// Licensed under the MIT license;
4+
// you may not use this file except in compliance with the License.
5+
//
6+
// Unless required by applicable law or agreed to in writing, software
7+
// distributed under the License is distributed on an "AS IS" BASIS,
8+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
// See LICENSE file in the project root for full license information.
10+
11+
using System.Text.Json.Serialization;
12+
13+
namespace Serilog.Sinks.Grafana.Loki.Models;
14+
15+
[JsonSerializable(typeof(LokiBatch))]
16+
internal sealed partial class LokiSerializationContext : JsonSerializerContext
17+
{
18+
}

src/Serilog.Sinks.Grafana.Loki/Serilog.Sinks.Grafana.Loki.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525

2626
<ItemGroup>
2727
<PackageReference Include="Serilog" Version="2.12.0" />
28-
<PackageReference Include="System.Text.Json" Version="4.7.0" />
28+
<PackageReference Include="System.Text.Json" Version="8.0.5"
29+
Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'net5.0'" />
2930
</ItemGroup>
3031

3132
<ItemGroup>

0 commit comments

Comments
 (0)