Json.NET - Logging And Debugging

Logging feature can be implemented in Json.Net by making use of the ITraceWriter interface. MemoryTraceWriter and DiagnosticsTraceWriter are the two implementations of ITraceWrite available in Json.Net. The former implementation keeps the messages in memory and is not persisted in any storage medium and is useful for doing basic debugging. The later one writes messages to the tracelisteners that our application is using. Advantage of using TraceListeners is that the information is persisted and is available for reference even after the application is closed.

In this example, I am going to implement the MemoryTraceWrite for logging information as well as error messages

First I have created an instance of the ITraceWriter and set it to the TraceWriter property in JsonSerializerSettings instance. 

Also you implement your own trace writers by creating new logger classes by inheriting the ITraceWriter interface. By doing this way, you will be able to integrate it with your own logging framework,


No Comments

Add a Comment