Send stringified json to serilog as structured data
Asked Answered
C

0

8

I have: Serilog 2.7.1 .NET Framework 4.5.x

I have a stringified JSON with different structures. Example:

{
  "dto": {
    "id": "8d8cc96fa1b44186b28f2a90364e47d2",
    "userName": "case6",
    "display": true,
    "isFullUpdate": false
  }
}

I want to save it as structured data - not as stringified JSON.

There are 2 ways:

with better performance - to find formatter "stringified json" -> structured data another way - convert it to JObject before (worse on performance) - and after to structured data JsonConvert.DeserializeObject(myStringifiedJson) -> -> structured data (now as a result I have:

[21:34:27 INF] [[[]], [[]]])

There is a solution for netCore 2.0 - but not for .NET Framework 4.5.x (https://github.com/destructurama/json-net) If the current behaviour is a bug, please provide the steps to reproduce the issue and if possible a minimal demo of the problem

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.WriteTo.Console()
.CreateLogger();
var myStringifiedJson = @" {""dto"":{""id"":""8d8cc96fa1b44186b28f2a90364e47d2"",""userName"":""case6"",""display"":true,""isFullUpdate"":false}}";
var myJObject = JsonConvert.DeserializeObject(myStringifiedJson);
Log.Information("{@jobject}", myStringifiedJson); // just plaint text
Log.Information("{@jobject}", myJObject); // [[[]], [[]]])
Log.CloseAndFlush();
Cucurbit answered 26/10, 2018 at 9:10 Comment(2)
json-net library supports .NETFramework 4.5.2. Which .net version are you using?Fergus
.NETFramework 4.5.1Cucurbit

© 2022 - 2024 — McMap. All rights reserved.