Click or drag to resize
Json.NETTraceWriter setting
 

This sample uses an ITraceWriter to log debug information from serialization.

Sample
Types
1public class Account
2{
3    public string FullName { get; set; }
4    public bool Deleted { get; set; }
5}
Usage
 1string json = @"{
 2  'FullName': 'Dan Deleted',
 3  'Deleted': true,
 4  'DeletedDate': '2013-01-20T00:00:00'
 5}";
 6
 7MemoryTraceWriter traceWriter = new MemoryTraceWriter();
 8
 9Account account = JsonConvert.DeserializeObject<Account>(json, new JsonSerializerSettings
10{
11    TraceWriter = traceWriter
12});
13
14Console.WriteLine(traceWriter.ToString());
15// 2013-01-21T01:36:24.422 Info Started deserializing Newtonsoft.Json.Tests.Documentation.Examples.TraceWriter+Account. Path 'FullName', line 2, position 20.
16// 2013-01-21T01:36:24.442 Verbose Could not find member 'DeletedDate' on Newtonsoft.Json.Tests.Documentation.Examples.TraceWriter+Account. Path 'DeletedDate', line 4, position 23.
17// 2013-01-21T01:36:24.447 Info Finished deserializing Newtonsoft.Json.Tests.Documentation.Examples.TraceWriter+Account. Path '', line 5, position 8.
18// 2013-01-21T01:36:24.450 Verbose Deserialized JSON: 
19// {
20//   "FullName": "Dan Deleted",
21//   "Deleted": true,
22//   "DeletedDate": "2013-01-20T00:00:00"
23// }