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.
I checked again in a completely separate project and as Ross Patterson suggests, the exception trace is correct.
Unfortunately I already refactored my (large) project with Debugger.IsAttached and the problem went away so I (groundlessly as it turns out) suspected that preprocessor directives were the issue. Maybe the .pdb were not in sync with the binaries.
Since I'm unable to reproduce the issue now I consider it solved. It's good to know that this scenario is supported. Thanks Ross Patterson!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With