Skip to content

Commit 90bdf0c

Browse files
authored
Merge pull request #335 from datalust/dev
2024.2 Release
2 parents ef63388 + 1e226b5 commit 90bdf0c

File tree

4 files changed

+96
-6
lines changed

4 files changed

+96
-6
lines changed

global.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "8.0.101"
3+
"version": "8.0.203"
44
}
5-
}
5+
}

src/SeqCli/Cli/Features/OutputFormatFeature.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414

1515
using System;
1616
using System.Collections.Generic;
17-
using Destructurama;
1817
using Newtonsoft.Json;
1918
using Newtonsoft.Json.Converters;
2019
using Newtonsoft.Json.Linq;
2120
using Seq.Api.Model;
2221
using SeqCli.Config;
2322
using SeqCli.Csv;
2423
using SeqCli.Output;
24+
using SeqCli.Util;
2525
using Serilog;
2626
using Serilog.Core;
2727
using Serilog.Events;
@@ -122,7 +122,7 @@ public void WriteEntity(Entity entity)
122122
// way to write colorized JSON ;)
123123

124124
var writer = new LoggerConfiguration()
125-
.Destructure.JsonNetTypes()
125+
.Destructure.With<JsonNetDestructuringPolicy>()
126126
.Enrich.With<StripStructureTypeEnricher>()
127127
.WriteTo.Console(
128128
outputTemplate: "{@Message:j}{NewLine}",

src/SeqCli/SeqCli.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
</Content>
2828
</ItemGroup>
2929
<ItemGroup>
30-
<PackageReference Include="Destructurama.JsonNet" Version="2.0.1" />
3130
<PackageReference Include="newtonsoft.json" Version="13.0.3" />
3231
<PackageReference Include="Serilog" Version="3.1.1" />
3332
<PackageReference Include="Serilog.Expressions" Version="4.0.0" />
@@ -39,7 +38,7 @@
3938
<PackageReference Include="Superpower" Version="3.0.0" />
4039
<PackageReference Include="System.Reactive" Version="6.0.0" />
4140
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="8.0.0" />
42-
<PackageReference Include="Seq.Api" Version="2024.1.0" />
41+
<PackageReference Include="Seq.Api" Version="2024.2.0" />
4342
<PackageReference Include="Seq.Apps" Version="2023.4.0" />
4443
<PackageReference Include="Seq.Syntax" Version="1.0.0" />
4544
<PackageReference Include="Tavis.UriTemplates" Version="2.0.0" />
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright 2015 Destructurama Contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System.Collections.Generic;
16+
using System.Diagnostics.CodeAnalysis;
17+
using System.Linq;
18+
using Newtonsoft.Json.Linq;
19+
using Serilog.Core;
20+
using Serilog.Events;
21+
22+
namespace SeqCli.Util;
23+
24+
sealed class JsonNetDestructuringPolicy : IDestructuringPolicy
25+
{
26+
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, [NotNullWhen(true)] out LogEventPropertyValue? result)
27+
{
28+
switch (value)
29+
{
30+
case JObject jo:
31+
result = Destructure(jo, propertyValueFactory);
32+
return true;
33+
case JArray ja:
34+
result = Destructure(ja, propertyValueFactory);
35+
return true;
36+
case JValue jv:
37+
result = Destructure(jv, propertyValueFactory);
38+
return true;
39+
}
40+
41+
result = null;
42+
return false;
43+
}
44+
45+
static LogEventPropertyValue Destructure(JValue jv, ILogEventPropertyValueFactory propertyValueFactory)
46+
{
47+
return propertyValueFactory.CreatePropertyValue(jv.Value!, destructureObjects: true);
48+
}
49+
50+
static SequenceValue Destructure(JArray ja, ILogEventPropertyValueFactory propertyValueFactory)
51+
{
52+
var elems = ja.Select(t => propertyValueFactory.CreatePropertyValue(t, destructureObjects: true));
53+
return new SequenceValue(elems);
54+
}
55+
56+
static LogEventPropertyValue Destructure(JObject jo, ILogEventPropertyValueFactory propertyValueFactory)
57+
{
58+
string? typeTag = null;
59+
var props = new List<LogEventProperty>(jo.Count);
60+
61+
foreach (var prop in jo.Properties())
62+
{
63+
if (prop.Name == "$type")
64+
{
65+
if (prop.Value is JValue typeVal && typeVal.Value is string v)
66+
{
67+
typeTag = v;
68+
continue;
69+
}
70+
}
71+
else if (!LogEventProperty.IsValidName(prop.Name))
72+
{
73+
return DestructureToDictionaryValue(jo, propertyValueFactory);
74+
}
75+
76+
props.Add(new LogEventProperty(prop.Name, propertyValueFactory.CreatePropertyValue(prop.Value, destructureObjects: true)));
77+
}
78+
79+
return new StructureValue(props, typeTag);
80+
}
81+
82+
static DictionaryValue DestructureToDictionaryValue(JObject jo, ILogEventPropertyValueFactory propertyValueFactory)
83+
{
84+
var elements = jo.Properties().Select(
85+
prop => new KeyValuePair<ScalarValue, LogEventPropertyValue>(
86+
new ScalarValue(prop.Name),
87+
propertyValueFactory.CreatePropertyValue(prop.Value, destructureObjects: true))
88+
);
89+
return new DictionaryValue(elements);
90+
}
91+
}

0 commit comments

Comments
 (0)