Is there a TextWriter interface to the System.Diagnostics.Debug class?

前端 未结 4 1618
伪装坚强ぢ
伪装坚强ぢ 2020-12-30 22:16

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 ofte

4条回答
  •  爱一瞬间的悲伤
    2020-12-30 22:51

    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.

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

提交回复
热议问题