If I have ExpandoObject like this:
dynamic d = new ExpandoObject();
d.x = "a";
d.y = "b";
and log it with Serilog to RollingFile using JsonFormatter like this:
_logger.Debug("{@d}", d);
it will be serialised to json like this:
[{"_typeTag":"KeyValuePair`2","Key":"x","Value":"a"},{"_typeTag":"KeyValuePair`2","Key":"y","Value":"b"}]
If I use Newtonsoft.Json to serialise the same ExpandoObject like this:
JsonConvert.SerializeObject(d)
I will get this:
{"x":"a","y":"b"}
How can I make Serilog produce the same json as Newtonsoft.Json does?
Adding:
.Destructure.ByTransforming<ExpandoObject>(e => new Dictionary<string,object>(e))
to your LoggerConfiguration should do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With