When our application doesn't work the way we expect it to (e.g. throws exceptions etc.), I usually insert a lot of debug code at certain points in the application in order to get a better overview of what exactly is going on, what the values for certain objects are, to better trace where this error is triggered from. Then I send a new installer to the user(s) that are having the problem and if the problem is triggered again I look at the logs and see what they say.
But I don't want all this debug code to be in the production code, since this would create some really big debug files with information that is not always relevant.
The other problem is that our code base changes, and the next time, the same debug code might have to go in different parts of the application.
Is there a way to merge this debug code within the production code only when needed and have it appear at the correct points within the application?
Can it be done with a version control system like git so that all would be needed is a
P.S. The application I'm talking about now is .NET, written in C#.