简体   繁体   English

如何让Debug.WriteLine在发布模式下写入输出窗口?

[英]How do I get Debug.WriteLine to write to the output window in Release mode?

Ok, I realize that the question sounds ridiculous. 好吧,我意识到这个问题听起来很荒谬。 Why would you wanna debug in release mode? 为什么要在发布模式下调试? I'm trying to implement an ILogger interface that when implemented, provides a facade for logging (obviously). 我正在尝试实现一个ILogger接口,在实现时,它提供了一个用于记录的外观(显然)。 For the most part, that facade writes out to enterprise library -- so it already has a Debug method with it's own configuration. 在大多数情况下,该外观写入企业库 - 因此它已经有一个具有自己配置的Debug方法。 The problem is that I simply add Debug.WriteLine("msg") line to the facade in addition to it's normal behavior of writing out to a file, when I build it in Release mode, those debug statements don't get compiled with it so it won't write to the console when using that library from a different project, even if that project is built in debug. 问题是我只是简单地将Debug.WriteLine(“msg”)行添加到外观,除了它写出文件的正常行为,当我在发布模式下构建它时,那些调试语句不会用它编译所以当使用来自不同项目的库时,它不会写入控制台,即使该项目是在调试中构建的。

What I would like is to set up this facade so that regardless of how it is built, all Logger.Debug messages will be output to the window and not just the file generated by MEL. 我想要的是设置这个外观,这样无论它是如何构建的,所有Logger.Debug消息都将输出到窗口而不仅仅是MEL生成的文件。 Can I just set up the System.Diagnostics object to always compile, or is there a way to set up enterprise library to use the output as a configured listener? 我是否可以将System.Diagnostics对象设置为始终进行编译,还是有办法设置企业库以将输出用作已配置的侦听器?

You can use Trace.WriteLine instead. 您可以改用Trace.WriteLine Just make sure that TRACE is defined in the Release settings (it is by default). 只需确保在Release设置中定义TRACE (默认情况下)。

Technically speaking, you could make DEBUG defined in Release mode, either via project settings or explicitly: 从技术上讲,您可以通过项目设置或显式地在发布模式下定义DEBUG

#define DEBUG

But it would be weird. 但这很奇怪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM