Skip to main content

C# - Mining Object Model Data For The Sake Of TroubleShooting.

My photo
The Problem Statement
It is always challenging to debug our solution when we try to reproduce a certain bug/issue, It often easy to debug when it happen at a developer/programmer own dev machine, but things get really hard when the bug/issue happened at clients device or remote server. Using try/catch exception will help us on showing some hint on where the bug happen or what action actually violate our requirement. But it wont actually help us on trying to reproduce the bug, This is often due to the current state of the system and probably the object state that doesn't meet the requirement.

Consideration
This code base is proposed for the intention of specific problem domain that we might encounter throughout our development lifecycle, for production/release we might need to tweak it to meet the company policy, best practice and industry standards. The code snippet is free to use anywhere.

The Requirement
To help assist developer/programmer in trying to reproduce a specific bug/issue, We will try to gather as many information as possible alongside with our exception info that has been caught by our system. It would be really helpful if we able to log all the object state/properties that might be involved during the caught exception.

The Solution
We will create an CrashDataLogger to log the state/properties of a specific object during the caught exception, with these details, it will somehow assist us as a developer/programmer on tackling our bug/issue.

Create The CrashDataLogger Helper
We will start by creating a simple static helper class to help us on iterating our object properties, these properties and its value will be saved in an instance of Dictionary before we log the data. We then may log the exceptions details alongside with our crash data. Implementation
Assuming we have a xamarin app at the client side, and its working on its own local data store. Somehow there is data relationship violated and might break our code. For whatever reason it might happen, we may make use the CrashDataLogger to log the data alongside with its exception and report it to our side.

Conclusion
From here we may conclude that, at a certain situation, we might need to perform extra logging details in assisting our developer/programmer in reproducing bugs/issues. This can be done by logging the data that involved during the error. Since this is based on .Net Framework 4.5, this can be done by using system.reflection prior to legacy framework.

Published on : 26-December-2018
Ref no : DDN-WPUB-000212

About Author

My photo
Wan Mohd Adzha MCPD,MCSD,MCSE
I am passionate about technology and of course love Durians. Certified by Microsoft as MCP Since 2011. Blogging from Malaysia

Comments