System.Diagnostics.Debug.WriteLine in production code

吃可爱长大的小学妹 提交于 2019-11-28 05:11:03

All the members in the Debug class are marked with ConditionalAttribute, so the call sites won't be compiled into a Release build.

Mitch Wheat

System.Diagnostics.Debug method calls are only present when the "DEBUG" conditional compilation symbol is defined. By default, the "DEBUG" symbol is defined only for debug builds.

Compilers that support ConditionalAttribute ignore calls to these methods unless "DEBUG" is defined as a conditional compilation symbol.

Since the Debug methods all have the [Conditional("DEBUG")] attribute on them, if you switch from Debug to Release you will have not have to worry about it as the calls to those methods will be removed (along with the other optimizations of a Release build).

Debug information is only visible when you're running in Debug mode. In Release mode no Debug statements will be visible (you can use Trace instead of Debug if you want these statements to be visible in Release mode).

http://support.microsoft.com/kb/815788

Providing you compile without the /d:DEBUG option or #define DEBUG, your WriteLine calls will not physically present in your release code; there is no way for any third party to recover any information from these calls, as they literally not there in the release version.

More details here: Debug Class (System.Diagnostics) on MSDN

Almost all members of Debug are marked with ConditionalAttribute. Such compilers as C# will skip calls to those methods during Release build, so you are on the safe side.

Mode info here: http://msdn.microsoft.com/en-us/library/system.diagnostics.debug.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!