5

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.

4

1 回答 1

2

我再次检查了一个完全独立的项目,正如罗斯帕特森所说,异常跟踪是正确的。

不幸的是,我已经用 Debugger.IsAttached 重构了我的(大型)项目并且问题消失了,所以我(事实证明毫无根据)怀疑预处理器指令是问题所在。也许 .pdb 与二进制文件不同步。

由于我现在无法重现该问题,因此我认为它已解决。很高兴知道支持此方案。谢谢罗斯帕特森!_

于 2011-11-27T18:43:56.570 回答