When I use preprocessor directives like
1 #if(DEBUG)
2 // 1
3 // 2
4 #else
5 // 1
6 // 2
7 #endif
8
9 logger.Debug("Log exception, etc.");
it causes that at runtime the line numbers in the log (eg. stack trace) are incorrect - in the above example line 9 would become 4 because the rest would be parsed by the preprocessor.
It makes log analysis quite difficult.
Is there a way to solve this issue without creating methods with ConditionalAttribute
?
I'm aware of Debugger.IsAttached
(and I'm using this solution now) but I would prefer to run code based on the build mode (debug/release) not on whether the debugger is attached.