Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,41 @@ Install-Package Destructurama.JsonNet
Modify logger configuration:

```csharp
var log = new LoggerConfiguration()
.Destructure.JsonNetTypes()
...
var log = new LoggerConfiguration().Destructure.JsonNetTypes()
```

Any JSON.NET dynamic object can be represented in the log event's properties:
Now any JSON.NET dynamic object can be represented in the log event's properties:

```csharp
var obj = JsonConvert.DeserializeObject<dynamic>(someJson);
Log.Information("Deserialized {@Obj}", obj);
using Destructurama;
using Newtonsoft.Json;
using Serilog;

var logger1 = new LoggerConfiguration().WriteTo.Console().CreateLogger();
var logger2 = new LoggerConfiguration().Destructure.JsonNetTypes().WriteTo.Console().CreateLogger();

var json = """
{
"name": "Tom",
"age": 42,
"isDeveloper": true
}
""";

var obj = JsonConvert.DeserializeObject<dynamic>(json);

logger1.Information("Deserialized without JsonNetTypes(): {@Obj}", obj);

logger2.Information("Deserialized with JsonNetTypes(): {@Obj}", obj);

Console.ReadKey();
```

Output:

```
[20:27:59 INF] Deserialized without JsonNetTypes(): [[[]], [[]], [[]]]
[20:27:59 INF] Deserialized with JsonNetTypes(): {"name": "Tom", "age": 42, "isDeveloper": true}
```

# Benchmarks
Expand Down
22 changes: 22 additions & 0 deletions src/Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Destructurama;
using Newtonsoft.Json;
using Serilog;

var logger1 = new LoggerConfiguration().WriteTo.Console().CreateLogger();
var logger2 = new LoggerConfiguration().Destructure.JsonNetTypes().WriteTo.Console().CreateLogger();

var json = """
{
"name": "Tom",
"age": 42,
"isDeveloper": true
}
""";

var obj = JsonConvert.DeserializeObject<dynamic>(json);

logger1.Information("Deserialized without JsonNetTypes(): {@Obj}", obj);

logger2.Information("Deserialized with JsonNetTypes(): {@Obj}", obj);

Console.ReadKey();
16 changes: 16 additions & 0 deletions src/Sample/Sample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Destructurama.JsonNet\Destructurama.JsonNet.csproj" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions src/destructurama-json-net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Destructurama.JsonNet.Tests
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks", "Benchmarks\Benchmarks.csproj", "{1304D51F-FEE7-4D28-BE2C-7B60B0F3D217}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "Sample\Sample.csproj", "{48A94BF6-5979-4169-8BCB-BF129F7F364F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -64,6 +66,10 @@ Global
{1304D51F-FEE7-4D28-BE2C-7B60B0F3D217}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1304D51F-FEE7-4D28-BE2C-7B60B0F3D217}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1304D51F-FEE7-4D28-BE2C-7B60B0F3D217}.Release|Any CPU.Build.0 = Release|Any CPU
{48A94BF6-5979-4169-8BCB-BF129F7F364F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{48A94BF6-5979-4169-8BCB-BF129F7F364F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{48A94BF6-5979-4169-8BCB-BF129F7F364F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{48A94BF6-5979-4169-8BCB-BF129F7F364F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down