The two tasks must be completed by the debugger class. The system. Diagnostics. Debugger type allows us to interact with the debugger. It is easy to understand that there are not many members of the debugger type. (Msdn)
First, you must use the isattached attribute to determine whether the current process has attached a debugger. If so, use the islogging method to determine whether the current append debugger supports logging. If both are true, you can use the LOG method to record messages safely. The log Content is displayed in the Visual Studio output window.
The debugger. Break method forces the debugger to perform breakpoint processing when running the current code.
Code:
// + Using system. diagnostics;
// Determine whether a debugger is attached
// Determine whether the debugger supports message logs
If (debugger. isattached & debugger. islogging ())
{
// Record
Debugger. Log (1, "joke", "This code has to be well debugged! ");
// Add a breakpoint
Debugger. Break ();
}
Debug and run the above Code (you can directly press F5). Visual Studio will debug the breakpoint on the debugger. Break () line of code, and the output window will have our custom information, such: