A tool or framework extension or code snippet for logging the internal state of objects?

Posted by George Mauer on Stack Overflow See other posts from Stack Overflow or by George Mauer
Published on 2010-04-26T01:00:17Z Indexed on 2010/04/26 1:03 UTC
Read the original article Hit count: 416

Filed under:
|
|

When spiking on how something works or when my unit test behave in an unpredictable manner I usually have to drop into debug mode. 99% of my time in debug mode is spent checking the values of fields on objects to verify its state.

I already have log4net set up, it would seem that if I could easily add a line of code to log out the state of objects I could remove most of my need to start up the bulky debugger. The problem is of course that to expose object state implicitly you need to manually override each object's ToString() method. What I would like to be able to do is the ability to do logger.LogState(someObject) and have logged out the object state including at least a formatted list of all the private variables, references (to some arbitrary depth), and collections.

Does anyone know a tool/framework/code snippet that can be used to generate a string of the internal state of any object? I could of course write one myself but its a non-trivial problem and I'd prefer something someone has put some thought into.

© Stack Overflow or respective owner

Related posts about tools

Related posts about .NET