title: Log Console output of a C# Async Task when called from Powershell
body: <p>I am calling a C# DLL from my Powershell script with the following lines of code.</p>
  <pre><code>Add-Type -Path &quot;PATH_TO_DLL&quot;;
  $MyClass = New-Object -TypeName MyClass;
  $MyClass.MyMethod();
  </code></pre>
  <p>The <code>MyMethod()</code> method has the following signature:</p>
  <pre><code>public async Task MyMethod()
  </code></pre>
  <p>The <code>MyMethod()</code> code outputs stuff by using <code>System.Console.WriteLine()</code>. When I execute the powershell code via the powershell command line, I can see this output on the command line. However, if I want to output this to a separate log file by using <code>Start-Transcript ...</code> and <code>Stop-Transcript</code>, I only get a <code>VoidTaskResult</code> that looks as can be seen here: <a href="https://pastebin.com/xK76W0h2" rel="nofollow noreferrer">https://pastebin.com/xK76W0h2</a></p>
  <p>I already tried the solutions described in the following threads, but they did not yield the desired result for me. None of the log output that is written by the C# application with <code>System.Console.WriteLine()</code> is shown or logged. Why?</p>
  <p><a href="https://stackoverflow.com/questions/24370814/how-to-capture-process-output-asynchronously-in-powershell">How to capture process output asynchronously in powershell?</a></p>
  <p><a href="https://stackoverflow.com/questions/25851704/getting-result-of-net-object-asynchronous-method-in-powershell">Getting result of .Net object asynchronous method in powershell</a></p>