Skip to content

Commit 899e72b

Browse files
authored
Add sample (#72)
1 parent 4d1b190 commit 899e72b

File tree

4 files changed

+75
-6
lines changed

4 files changed

+75
-6
lines changed

README.md

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,41 @@ Install-Package Destructurama.JsonNet
3636
Modify logger configuration:
3737

3838
```csharp
39-
var log = new LoggerConfiguration()
40-
.Destructure.JsonNetTypes()
41-
...
39+
var log = new LoggerConfiguration().Destructure.JsonNetTypes()
4240
```
4341

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:
4543

4644
```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}
4974
```
5075

5176
# Benchmarks

src/Sample/Program.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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();

src/Sample/Sample.csproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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>

src/destructurama-json-net.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Destructurama.JsonNet.Tests
4646
EndProject
4747
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks", "Benchmarks\Benchmarks.csproj", "{1304D51F-FEE7-4D28-BE2C-7B60B0F3D217}"
4848
EndProject
49+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "Sample\Sample.csproj", "{48A94BF6-5979-4169-8BCB-BF129F7F364F}"
50+
EndProject
4951
Global
5052
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5153
Debug|Any CPU = Debug|Any CPU
@@ -64,6 +66,10 @@ Global
6466
{1304D51F-FEE7-4D28-BE2C-7B60B0F3D217}.Debug|Any CPU.Build.0 = Debug|Any CPU
6567
{1304D51F-FEE7-4D28-BE2C-7B60B0F3D217}.Release|Any CPU.ActiveCfg = Release|Any CPU
6668
{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
6773
EndGlobalSection
6874
GlobalSection(SolutionProperties) = preSolution
6975
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)