VisualStudio: no debug output

后端 未结 12 975
有刺的猬
有刺的猬 2020-12-24 03:13

I\'m trying to debug a C# application. The method:

System.Diagnostics.Debug.WriteLine(\"something\");

should do the work, but in the Output

12条回答
  •  天涯浪人
    2020-12-24 03:58

    You need to explicitly add the system's Console as a TraceListener in order for the output to appear in the console. According to Microsoft's documentation, this code should do the trick. This is C# code, but the link I provided contains examples for the other .NET languages.

    using System;
    using System.Data;
    using System.Diagnostics;
    
    class Test
    {
        static void Main()
        {
           Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
           Debug.AutoFlush = true;
           Debug.Indent();
           Debug.WriteLine("Entering Main");
           Console.WriteLine("Hello World.");
           Debug.WriteLine("Exiting Main"); 
           Debug.Unindent();
        }
    }
    

提交回复
热议问题