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
Connecting Azure Blob Storage account using Managed Identity
Posted 12/9/2022Securing Azure KeyVault connections using Managed Identity
Posted 11/26/2022Manage application settings with Azure KeyVault
Posted 11/9/2022Adding Serilog to Azure Functions created using .NET 5
Posted 4/3/2021Learn how to split log data into different tables using Serilog in ASP.NET Core
Posted 4/23/2020