跟踪与调试.NET BCL [英] Trace vs Debug in .NET BCL

查看:110
本文介绍了跟踪与调试.NET BCL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎

  • System.Diagnostics.Debug, and
  • System.Diagnostics.Trace

大致相同,显着的例外是在发布配置中编译了调试的用法。

are largely the same, with the notable exception that Debug usage is compiled out in a release configuration.

你什么时候使用而不是另一个?迄今为止我已经挖掘出来的唯一答案就是您使用 Debug 类来生成您只在调试配置中看到的输出,而跟踪将保留在一个发布配置,但这并没有真正回答我的头脑。

When would you use one and not the other? The only answer to this I've dug up so far is just that you use the Debug class to generate output that you only see in debug configuration, and Trace will remain in a release configuration, but that doesn't really answer the question in my head.

如果你要调整你的代码,为什么你会使用调试,因为跟踪可以关闭而不重新编译?

If you're going to instrument your code, why would you ever use Debug, since Trace can be turned off without a recompile?

推荐答案

区别是你指出的:调试不包括在版本中,而Trace是。

The main difference is the one you indicate: Debug is not included in release, while Trace is.

根据我的理解,预期的区别是,开发团队可能会使用Debug发出丰富的描述性消息,这些消息可能对产品的消费者来说太过详细(或泄露),而Trace旨在发布更专门用于测试应用程序的消息。

The intended difference, as I understand it, is that development teams might use Debug to emit rich, descriptive messages that might prove too detailed (or revealing) for the consumer(s) of a product, while Trace is intended to emit the kinds of messages that are more specifically geared toward instrumenting an application.

要回答最后一个问题,我想不出有什么理由使用Debug来编写我打算发行的一段代码。

To answer your last question, I can't think of a reason to use Debug to instrument a piece of code I intended to release.

希望这有帮助。

这篇关于跟踪与调试.NET BCL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆