Not all developers using Visual Studio are aware of the fact that you can use breakpoints to write to the debug window. This saves you from having calls to Debug.WriteLine littered throughout your code, which you may not want to check-in. The reason for not checking-in Debug.WriteLine calls is that it can clutter up the debug window for everyone working on the same source, making it hard for developers to pick out specific debug information they’ve added. Using a breakpoint allows you to keep the debug information local to your machine.
To make a breakpoint that writes to the debug window, create a breakpoint as you normally would and right-click on it to bring up its context menu. Then select the When Hit... menu item as shown below.
Check the Print a message: check box in the When Breakpoint Is Hit dialog and enter the text you want written to the debug window. In the screenshot below I’ve chosen to output the fully qualified method name followed by the value of the PropertyName property.
Make sure the Continue execution check box is checked to prevent the debugger from stopping at the breakpoint.
You can also combine multiple items in the breakpoint context menu. For example, you can select the Condition... menu item in addition to the When Hit... menu item to write to the debug window only when a condition is either true or has changed.
All of this without having to make a single call to Debug.WriteLine. May it rest in piece J.
I find I bearly use debug statements when I change my style to TDD. Can be handy for debugging legacy code though.
ReplyDelete