How can I output simple debugging messages
来源:互联网 发布:mac玫红色口红哪个最火 编辑:程序博客网 时间:2024/05/24 02:31
How can I output simple debugging messages?
Although Visual Studio sports many useful debugging features including line-by-line stepping through source code, there are times when outputting simple text strings with variable values for debugging is more efficient.
By using the Write
* methods of the System.Diagnostics.Debug
class, messages can be output in a way similar to theOutputDebugString
function of the Win32 API. But, the charm of the Debug
class is that when building an application using the default Visual Studio Release configuration, no source code lines are generated for yourDebug.Write
* class. Therefore, no performance penalty is incurred by using the Debug class in release code.
To use the Debug
class, follow this example:
using System.Diagnostics; Debug.Write ("Debugging string");
In addition to the Write
method, WriteIf
, WriteLine
, andWriteLineIf
may be called. Here is a brief example:
bool @flag1 = true;bool flag2 = false;Debug.WriteLineIf (@flag1 || flag2, "Conditional debug message!");
When debugging an application with the Visual Studio debugger, all messages emitted byWrite
method calls show up in the Output window (View / Output menu command or Ctrl+W,O). However, when running an application outside the debugger—e.g., after starting it from Windows Explorer—, the messages can still be viewed using tools such as DebugView
of Sysinternals
.
Note: If the application is built using the default Release configuration, not even DebugView will display the messages; because, theDebug.Write
* calls are completely eliminated. Also, code generation can be controlled by defining theDEBUG
conditional directive.
Tip: The .NET debugging and tracing architecture allows redirecting debugging messages to various destinations,e.g. text files.
http://en.csharp-online.net/CSharp_FAQ%3A_How_can_I_output_simple_debugging_messages- How can I output simple debugging messages
- How can I capture the audio output with GStreamer?
- How Can I Stop
- How can i get FWHM?
- Cannot retrieve debugging output.
- How can I create a tray icon
- How can I create a tray icon
- How can I overclock my video card?
- How can I flip a UIImageView?
- How can I print a JavaScript object?
- How can I launch Matlab 2012?
- How can i style an Android Switch?
- How can I remove this user
- How can I style an Android Switch?
- How can I become data scientist?FAQ
- How can i batch copy/process categories
- Hibernate OR MyBatis,How can I choose?
- How can I kill defunc proc?
- 独眼戎龙
- 教你对Windows干点坏事,各种钩子的使用
- PB基本...
- 在没有安装 ASP.NET MVC3 的服务器上运行 MVC3
- CSS里面的behavior属性的作用是什么,怎么使用
- How can I output simple debugging messages
- 用数学软件分析这么多的数据```
- oracle dml流程
- 嗯~!
- 如何用 opencv 训练自己的分类器
- 近期笔试题C/C++---1
- 三层构架
- Effective c++学习笔记——条款08:别让异常逃离析构函数
- li{ star : expression(onmouseover=function()