Sometimes we need to make some write to logs, trace, and maybe limit some features during debug. It's good to know that in debug mode we have precompiler identifier DEBUG is set. So, first of all you can try #if #endif construction. In my opinion, it's not very good to use #if directive, especialy if there is something better.
Conditional attribute. It can be applied to any method that returns void. Why void? Because the method call ignored if the condition is not fulfilled. The method can be static or not.
[Conditional("DEBUG")] static void DebugMethod() { }
So, this is the best way to make some job in DEBUG configuration. Also, it can be used to make different build configurations.
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.