File tree Expand file tree Collapse file tree 4 files changed +75
-6
lines changed Expand file tree Collapse file tree 4 files changed +75
-6
lines changed Original file line number Diff line number Diff line change @@ -36,16 +36,41 @@ Install-Package Destructurama.JsonNet
36
36
Modify logger configuration:
37
37
38
38
``` csharp
39
- var log = new LoggerConfiguration ()
40
- .Destructure .JsonNetTypes ()
41
- .. .
39
+ var log = new LoggerConfiguration ().Destructure .JsonNetTypes ()
42
40
```
43
41
44
- Any JSON .NET dynamic object can be represented in the log event 's properties:
42
+ Now any JSON .NET dynamic object can be represented in the log event 's properties:
45
43
46
44
```csharp
47
- var obj = JsonConvert .DeserializeObject <dynamic >(someJson );
48
- Log .Information (" Deserialized {@Obj}" , obj );
45
+ using Destructurama ;
46
+ using Newtonsoft .Json ;
47
+ using Serilog ;
48
+
49
+ var logger1 = new LoggerConfiguration ().WriteTo .Console ().CreateLogger ();
50
+ var logger2 = new LoggerConfiguration ().Destructure .JsonNetTypes ().WriteTo .Console ().CreateLogger ();
51
+
52
+ var json = """
53
+ {
54
+ "name": "Tom",
55
+ "age": 42,
56
+ "isDeveloper": true
57
+ }
58
+ """ ;
59
+
60
+ var obj = JsonConvert .DeserializeObject <dynamic >(json );
61
+
62
+ logger1 .Information (" Deserialized without JsonNetTypes(): {@Obj}" , obj );
63
+
64
+ logger2 .Information (" Deserialized with JsonNetTypes(): {@Obj}" , obj );
65
+
66
+ Console .ReadKey ();
67
+ ```
68
+
69
+ Output:
70
+
71
+ ```
72
+ [20:27:59 INF] Deserialized without JsonNetTypes(): [[[]], [[]], [[]]]
73
+ [20:27:59 INF] Deserialized with JsonNetTypes(): {"name": "Tom", "age": 42, "isDeveloper": true}
49
74
```
50
75
51
76
# Benchmarks
Original file line number Diff line number Diff line change
1
+ using Destructurama ;
2
+ using Newtonsoft . Json ;
3
+ using Serilog ;
4
+
5
+ var logger1 = new LoggerConfiguration ( ) . WriteTo . Console ( ) . CreateLogger ( ) ;
6
+ var logger2 = new LoggerConfiguration ( ) . Destructure . JsonNetTypes ( ) . WriteTo . Console ( ) . CreateLogger ( ) ;
7
+
8
+ var json = """
9
+ {
10
+ "name": "Tom",
11
+ "age": 42,
12
+ "isDeveloper": true
13
+ }
14
+ """ ;
15
+
16
+ var obj = JsonConvert . DeserializeObject < dynamic > ( json ) ;
17
+
18
+ logger1 . Information ( "Deserialized without JsonNetTypes(): {@Obj}" , obj ) ;
19
+
20
+ logger2 . Information ( "Deserialized with JsonNetTypes(): {@Obj}" , obj ) ;
21
+
22
+ Console . ReadKey ( ) ;
Original file line number Diff line number Diff line change
1
+ <Project Sdk =" Microsoft.NET.Sdk" >
2
+
3
+ <PropertyGroup >
4
+ <OutputType >Exe</OutputType >
5
+ <TargetFramework >net9.0</TargetFramework >
6
+ </PropertyGroup >
7
+
8
+ <ItemGroup >
9
+ <PackageReference Include =" Serilog.Sinks.Console" Version =" 6.0.0" />
10
+ </ItemGroup >
11
+
12
+ <ItemGroup >
13
+ <ProjectReference Include =" ..\Destructurama.JsonNet\Destructurama.JsonNet.csproj" />
14
+ </ItemGroup >
15
+
16
+ </Project >
Original file line number Diff line number Diff line change @@ -46,6 +46,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Destructurama.JsonNet.Tests
46
46
EndProject
47
47
Project ("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}" ) = "Benchmarks" , "Benchmarks\Benchmarks.csproj" , "{1304D51F-FEE7-4D28-BE2C-7B60B0F3D217}"
48
48
EndProject
49
+ Project ("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" ) = "Sample" , "Sample\Sample.csproj" , "{48A94BF6-5979-4169-8BCB-BF129F7F364F}"
50
+ EndProject
49
51
Global
50
52
GlobalSection (SolutionConfigurationPlatforms ) = preSolution
51
53
Debug| Any CPU = Debug| Any CPU
@@ -64,6 +66,10 @@ Global
64
66
{1304D51F-FEE7-4D28-BE2C-7B60B0F3D217} .Debug| Any CPU .Build .0 = Debug| Any CPU
65
67
{1304D51F-FEE7-4D28-BE2C-7B60B0F3D217} .Release| Any CPU .ActiveCfg = Release| Any CPU
66
68
{1304D51F-FEE7-4D28-BE2C-7B60B0F3D217} .Release| Any CPU .Build .0 = Release| Any CPU
69
+ {48A94BF6-5979-4169-8BCB-BF129F7F364F} .Debug| Any CPU .ActiveCfg = Debug| Any CPU
70
+ {48A94BF6-5979-4169-8BCB-BF129F7F364F} .Debug| Any CPU .Build .0 = Debug| Any CPU
71
+ {48A94BF6-5979-4169-8BCB-BF129F7F364F} .Release| Any CPU .ActiveCfg = Release| Any CPU
72
+ {48A94BF6-5979-4169-8BCB-BF129F7F364F} .Release| Any CPU .Build .0 = Release| Any CPU
67
73
EndGlobalSection
68
74
GlobalSection (SolutionProperties ) = preSolution
69
75
HideSolutionNode = FALSE
You can’t perform that action at this time.
0 commit comments