Litter your code with logging calls.
Put it into a method that you call.. but mark it with the Conditional
attribute so that the calls are optimized out of a Release build:
[Conditional("DEBUG")] // calls are optimized away
public static void Log(string message) {
// implement logging logic here
}