I have a code that should run only in debug mo开发者_运维技巧de.
Is it better to use HttpContext.Current.IsDebuggingEnabled or "#if DEBUG ... #endif"?
Thanks,
Those are 2 completely different things!
HttpContext.Current.IsDebuggingEnabled
is related to the current web.config setting
debug=true
where
#if DEBUG ... #endif
is related to the project configuration debug/release setting at build time
Be carefull!
If the debug code should absolutely not be compiled into your release assemblies, then it's better to use #if
style (or consider using conditional methods).
When using #if DEBUG
blocks (or conditional methods), the code will not be compiled into your assembly if the build is not a Debug
build i.e. the DEBUG
compilation symbol is not defined.
The pre-processor directive (#if DEBUG ...
) has the advantage that the debugging code will not make it into the production environment, so there is zero possibility of it being executed (assuming you have effective configuration management procedures!)
精彩评论