The Json.NET serializer supports logging and debugging using the T:Newtonsoft.Json.Serialization.ITraceWriter interface. By assigning a trace writer you can capture serialization messages and errors, and debug what happens inside the Json.NET serializer when serializing and deserializing JSON.

# ITraceWriter

A trace writer can be assigned using properties on JsonSerializerSettings or JsonSerializer.

Debugging serialization using MemoryTraceWriter

Json.NET has two implementations of ITraceWriter: T:Newtonsoft.Json.Serialization.MemoryTraceWriter which keeps messages in memory for simple debugging like the example above, and T:Newtonsoft.Json.Serialization.DiagnosticsTraceWriter which writes messages to any System.Diagnostics.TraceListeners your application is using.

# Custom ITraceWriter

To write messages using your existing logging framework just implement a custom version of ITraceWriter.

Custom NLog TraceWriter

T:Newtonsoft.Json.JsonSerializer
T:Newtonsoft.Json.Serialization.ITraceWriter
T:Newtonsoft.Json.Serialization.MemoryTraceWriter
T:Newtonsoft.Json.Serialization.DiagnosticsTraceWriter