diff --git a/README.md b/README.md index 67edaa9..3593695 100644 --- a/README.md +++ b/README.md @@ -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(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(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 diff --git a/src/Sample/Program.cs b/src/Sample/Program.cs new file mode 100644 index 0000000..5a83023 --- /dev/null +++ b/src/Sample/Program.cs @@ -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(json); + +logger1.Information("Deserialized without JsonNetTypes(): {@Obj}", obj); + +logger2.Information("Deserialized with JsonNetTypes(): {@Obj}", obj); + +Console.ReadKey(); diff --git a/src/Sample/Sample.csproj b/src/Sample/Sample.csproj new file mode 100644 index 0000000..ca35371 --- /dev/null +++ b/src/Sample/Sample.csproj @@ -0,0 +1,16 @@ + + + + Exe + net9.0 + + + + + + + + + + + diff --git a/src/destructurama-json-net.sln b/src/destructurama-json-net.sln index ca0ce01..43e4b01 100644 --- a/src/destructurama-json-net.sln +++ b/src/destructurama-json-net.sln @@ -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 @@ -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