是否有一个的TextWriter接口System.Diagnostics.Debug类? [英] Is there a TextWriter interface to the System.Diagnostics.Debug class?

查看:86
本文介绍了是否有一个的TextWriter接口System.Diagnostics.Debug类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常被System.Diagnostics.Debug.Write /的WriteLine方法受挫。我想用写/的WriteLine方法从的TextWriter类的熟悉,所以我经常写

I'm often frustrated by the System.Diagnostics.Debug.Write/WriteLine methods. I would like to use the Write/WriteLine methods familiar from the TextWriter class, so I often write

Debug.WriteLine("# entries {0} for connection {1}", countOfEntries, connection);

这会导致一个编译器错误。我最后写

which causes a compiler error. I end up writing

Debug.WriteLine(string.Format("# entries {0} for connection {1}", 
    countOfEntries, connection));

这是非常尴尬的。

which is really awkward.

是否CLR有自TextWriter类派生的包装System.Debug,或者我应该推出自己的?

Does the CLR have a class deriving from TextWriter that "wraps" System.Debug, or should I roll my own?

推荐答案

你特别需要一个整体的TextWriter ?虽然这多少有些快速和肮脏我怀疑是静态类,只有几个方法会做得很清楚:

Do you particularly need a whole TextWriter? While this is somewhat "quick and dirty" I suspect a static class with just a few methods would do perfectly well:

public static class DebugEx
{
    [Conditional("DEBUG")]
    public static void WriteLine(string format, params object[] args)
    {
        Debug.WriteLine(string.Format(format, args));
    }
}

或类似的东西。

or something similar.

你要知道,我会亲自考察一下log4net的给予更多的控制输出。

Mind you, I'd personally look at something like log4net to give more control over the output.

这篇关于是否有一个的TextWriter接口System.Diagnostics.Debug类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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