title: Writing to Visual Studio output window, the sure-fire way
body: <p>Exactly as what asked in "<a href="https://stackoverflow.com/questions/9466838/">Writing to output window of Visual Studio?</a>", however solving the <em>remaining issue</em> -- </p>
  
  <ul>
  <li><blockquote>
    <p>I assume there is no way to write to output if i start without debugging (ctrl-f5) right? – previous_developer Feb 27 '12</p>
  </blockquote></li>
  <li><blockquote>
    <p>Debug.WriteLine() will only work when running in Debug. That means running it with F5 and not CTRL-F5.  – kirk.burleson Jul 15 '13 </p>
  </blockquote></li>
  </ul>
  
  <p>However, it is not the case because:</p>
  
  <ul>
  <li><blockquote>
    <p>Just ran a small app here, works fine for me. Perhaps there is a small glitch in your environment? – Bhargav Bhat Feb 27 '12</p>
  </blockquote></li>
  <li>Moreover, </li>
  </ul>
  
  <p>I can see some Informational printed in Visual Studio output window <em>during normal run</em>:</p>
  
  <pre><code>[1/10/2018 11:56:25 AM Informational] ------ Run test started ------
  [1/10/2018 11:56:26 AM Informational] NUnit Adapter 3.9.0.0: Test execution started
  [1/10/2018 11:56:26 AM Informational] Running selected tests in  ...\Demo.dll
  [1/10/2018 11:56:26 AM Informational] NUnit3TestExecutor converted 14 of 14 NUnit test cases
  [1/10/2018 11:56:45 AM Informational] NUnit Adapter 3.9.0.0: Test execution complete
  [1/10/2018 11:56:45 AM Informational] ========== Run test finished: 1 run (0:00:19.3066647) ==========
  </code></pre>
  
  <p>For to run in debug mode, The NUnit debug output will look like:</p>
  
  <pre><code>[1/10/2018 2:56:55 PM Informational] ------ Run test started ------
  [1/10/2018 2:56:56 PM Informational] NUnit Adapter 3.9.0.0: Test execution started
  [1/10/2018 2:56:56 PM Informational] Debugging selected tests in ...\Demo.dll
  [1/10/2018 2:56:57 PM Informational] NUnit3TestExecutor converted 14 of 14 NUnit test cases
  [1/10/2018 3:03:38 PM Informational] NUnit Adapter 3.9.0.0: Test execution complete
  [1/10/2018 3:03:38 PM Informational] ========== Run test finished: 1 run (0:06:43.6161412) ==========
  </code></pre>
  
  <p>I.e., regardless normal run or in debug mode, NUnit Adapter is able to write to the Visual Studio output window, the difference is only in the text "<em>Running selected tests</em>" or "<em>Debugging selected tests</em>"</p>
  
  <p>So, here is the summary of debugging output cases <strong>during normal run</strong>, <em>not in debug mode</em>:</p>
  
  <ul>
  <li>For C# Console, both <code>Debug.WriteLine</code> and <code>Trace.WriteLine</code> works fine. I've created and verified with this: <a href="https://pastebin.com/Du6ZbDV3" rel="nofollow noreferrer">https://pastebin.com/Du6ZbDV3</a></li>
  <li>However for Class/Form etc that don't have Console, neither <code>Debug.WriteLine</code> nor <code>Trace.WriteLine</code> work. Example:  <a href="https://pastebin.com/b7P0bYEa" rel="nofollow noreferrer">https://pastebin.com/b7P0bYEa</a>. "<em>It is pretty simple but still nothing – previous-developer Feb 27 '12</em>".</li>
  <li>In NUnit testing, which is C# Class lib, neither <code>Debug.WriteLine</code> nor <code>Trace.WriteLine</code> works. I've run mine several times and can confirm this. I'll not be posting my test code here because it is lengthy &amp; needs lots of libs to work, moreover, it is caused by the same glitch as <a href="https://pastebin.com/b7P0bYEa" rel="nofollow noreferrer">https://pastebin.com/b7P0bYEa</a>. </li>
  </ul>
  
  <p>So all in all, How to write to Visual Studio output window from class lib or win forms? </p>