The Debug.WriteIf method allows you to write the debug to the listener only when a condition is true. See below for an example.
Debug.WriteIf
Debug.WriteLineIc(counter ==100, "you have reached a maximum");