Skip to content

Repository files navigation

Destructurama.JsonNet

License

codecovNugetNuget

GitHub Release DateGitHub commits since latest release (by date)Size

GitHub contributorsActivityActivityActivity

Run unit testsPublish preview to GitHub registryPublish release to Nuget registryCodeQL analysis

Adds support for logging JSON.NET dynamic types as structured data with Serilog. For System.Text.Json dynamic types see this repo.

Installation

Install from NuGet:

Install-Package Destructurama.JsonNet

Usage

Modify logger configuration:

varlog=newLoggerConfiguration().Destructure.JsonNetTypes()

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

usingDestructurama;usingNewtonsoft.Json;usingSerilog;varlogger1=newLoggerConfiguration().WriteTo.Console().CreateLogger();varlogger2=newLoggerConfiguration().Destructure.JsonNetTypes().WriteTo.Console().CreateLogger();varjson=""" { "name": "Tom", "age": 42, "isDeveloper": true } """;varobj=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

The results are available here.

About

Adds support for logging JSON.NET dynamic types as structured data with Serilog

Resources

Stars

50 stars

Watchers

7 watching

Forks

Releases

Packages

Used by

Contributors

Languages