1. <legend id='C3KXJ'><style id='C3KXJ'><dir id='C3KXJ'><q id='C3KXJ'></q></dir></style></legend>

    2. <i id='C3KXJ'><tr id='C3KXJ'><dt id='C3KXJ'><q id='C3KXJ'><span id='C3KXJ'><b id='C3KXJ'><form id='C3KXJ'><ins id='C3KXJ'></ins><ul id='C3KXJ'></ul><sub id='C3KXJ'></sub></form><legend id='C3KXJ'></legend><bdo id='C3KXJ'><pre id='C3KXJ'><center id='C3KXJ'></center></pre></bdo></b><th id='C3KXJ'></th></span></q></dt></tr></i><div id='C3KXJ'><tfoot id='C3KXJ'></tfoot><dl id='C3KXJ'><fieldset id='C3KXJ'></fieldset></dl></div>

        <small id='C3KXJ'></small><noframes id='C3KXJ'>

          <bdo id='C3KXJ'></bdo><ul id='C3KXJ'></ul>
        <tfoot id='C3KXJ'></tfoot>

        Console.WriteLine 在哪里调试?

        时间:2023-08-27

      1. <i id='EedLd'><tr id='EedLd'><dt id='EedLd'><q id='EedLd'><span id='EedLd'><b id='EedLd'><form id='EedLd'><ins id='EedLd'></ins><ul id='EedLd'></ul><sub id='EedLd'></sub></form><legend id='EedLd'></legend><bdo id='EedLd'><pre id='EedLd'><center id='EedLd'></center></pre></bdo></b><th id='EedLd'></th></span></q></dt></tr></i><div id='EedLd'><tfoot id='EedLd'></tfoot><dl id='EedLd'><fieldset id='EedLd'></fieldset></dl></div>

          <tbody id='EedLd'></tbody>

            <small id='EedLd'></small><noframes id='EedLd'>

                <bdo id='EedLd'></bdo><ul id='EedLd'></ul>

                  <legend id='EedLd'><style id='EedLd'><dir id='EedLd'><q id='EedLd'></q></dir></style></legend><tfoot id='EedLd'></tfoot>

                  本文介绍了Console.WriteLine 在哪里调试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我找到了这个问题,但我想知道什么不同 - Console.WriteLine 的输出在调试时会去任何地方吗?我知道要让它进入输出窗口我应该 Debug.WriteLine() 或其他方法,但是标准 Console.WriteLine() 去哪里了?

                  I found this question, but what I want to know is different - does the output from Console.WriteLine go anywhere when debugging? I know that for it to go to the output window I should should Debug.WriteLine() or other methods, but where does the standard Console.WriteLine() go?

                  编辑调试时,您看不到黑色控制台窗口/测试日志 - 所以真正的问题是如何在调试期间访问/查看此输出?

                  Edit When debugging, you don't see the black console window / test log - so the real question is how can I access/view this output during debugging?

                  推荐答案

                  控制台可以将其输出重定向到任何文本编写器.如果您实现了一个写入 Diagnostics.Debug 的文本编写器,那么一切就绪.

                  The console can redirect it's output to any textwriter. If you implement a textwriter that writes to Diagnostics.Debug, you are all set.

                  这是一个写入调试器的文本编写器.

                  Here's a textwriter that writes to the debugger.

                  using System.Diagnostics;
                  using System.IO;
                  using System.Text;
                  
                  namespace TestConsole
                  {
                      public class DebugTextWriter : TextWriter
                      {
                          public override Encoding Encoding
                          {
                              get { return Encoding.UTF8; }
                          }
                  
                          //Required
                          public override void Write(char value)
                          {
                              Debug.Write(value);
                          }
                  
                          //Added for efficiency
                          public override void Write(string value)
                          {
                              Debug.Write(value);
                          }
                  
                          //Added for efficiency
                          public override void WriteLine(string value)
                          {
                              Debug.WriteLine(value);
                          }
                      }
                  }
                  

                  由于它使用 Diagnostics.Debug,因此它会遵循您的编译器设置来确定是否应该写入任何输出.此输出也可以在 Sysinternals DebugView 中看到.

                  Since it uses Diagnostics.Debug it will adhere to your compiler settings to wether it should write any output or not. This output can also be seen in Sysinternals DebugView.

                  这是你如何使用它:

                  using System;
                  
                  namespace TestConsole
                  {
                      class Program
                      {
                          static void Main(string[] args)
                          {
                              Console.SetOut(new DebugTextWriter());
                              Console.WriteLine("This text goes to the Visual Studio output window.");
                          }
                      }
                  }
                  

                  如果您想在发布模式下编译时在 Sysinternals DebugView 中查看输出,可以使用写入 OutputDebugString API 的 TextWriter.它可能看起来像这样:

                  If you want to see the output in Sysinternals DebugView when you are compiling in Release mode, you can use a TextWriter that writes to the OutputDebugString API. It could look like this:

                  using System.IO;
                  using System.Runtime.InteropServices;
                  using System.Text;
                  
                  namespace TestConsole
                  {
                      public class OutputDebugStringTextWriter : TextWriter
                      {
                          [DllImport("kernel32.dll")]
                          static extern void OutputDebugString(string lpOutputString);
                  
                          public override Encoding Encoding
                          {
                              get { return Encoding.UTF8; }
                          }
                  
                          //Required
                          public override void Write(char value)
                          {
                              OutputDebugString(value.ToString());
                          }
                  
                          //Added for efficiency
                          public override void Write(string value)
                          {
                              OutputDebugString(value);
                          }
                  
                          //Added for efficiency
                          public override void WriteLine(string value)
                          {
                              OutputDebugString(value);
                          }
                      }
                  }
                  

                  这篇关于Console.WriteLine 在哪里调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在屏幕左下角放置一个小控制台窗口? 下一篇:我可以从 C# 控制台窗口获得复制/粘贴功能吗?

                  相关文章

                  最新文章

                  1. <tfoot id='xswgG'></tfoot>
                      <bdo id='xswgG'></bdo><ul id='xswgG'></ul>

                    <small id='xswgG'></small><noframes id='xswgG'>

                  2. <legend id='xswgG'><style id='xswgG'><dir id='xswgG'><q id='xswgG'></q></dir></style></legend>
                    <i id='xswgG'><tr id='xswgG'><dt id='xswgG'><q id='xswgG'><span id='xswgG'><b id='xswgG'><form id='xswgG'><ins id='xswgG'></ins><ul id='xswgG'></ul><sub id='xswgG'></sub></form><legend id='xswgG'></legend><bdo id='xswgG'><pre id='xswgG'><center id='xswgG'></center></pre></bdo></b><th id='xswgG'></th></span></q></dt></tr></i><div id='xswgG'><tfoot id='xswgG'></tfoot><dl id='xswgG'><fieldset id='xswgG'></fieldset></dl></div>