The namespace System.Diagnostics provides a set of attributes and classes to interact with the system process, events managers, performance counts, etc. This namespace can help us too in debugging job.
Let’s review the useful actions inside of System.Diagnostics namespace.
DebuggerDisplay attribute drives the string format with debug screen show the value of: class, properties or fields.
This attribute supports delegates, properties, fields and assamblies.
DebuggerHidden attribute prevents the compiler stop in constructors, methods, properties and indexers declarations.
In mentioning this latter area, my comment might sound lightweight, but in the practice this can save time push key F11 in debugging.
Occasionally, we can’t debug the code of a library, service, etc, because it isn’t accessible or we can’t add project to our solution. In this case we can use the Debugger.Launch() method and Visual Studio open a debug window and we can debugger its code.
When executed the line Systen.Diagnostics.Debbuger.Launch(), open a MessageBox with the instance of Visual Studio Debugger Options:
In this window we can choose if we open a new stance of Visual Studio (all versions) or if we re-use a exist instance.
And we can debug the code:
Condition attribute allows to indicate a condition to methods so that the compiler, executes or no executes its content.
We can use with the precompiler sentences as DEBUG.
Will only run if the Solutions Configurations is Debug.
It doesn’t exist a condition for RELEASE, therefore we will use a define directives.
Define directives is another way to use System.Diagnostics.Conditional:
These are the useful tips and traps of System.Diagnostics. They are become very practical on many cases and I hope you.