title: Redirect Trace output to Console
body: <p>Let's say I'm working on a little batch-processing console app in VB.Net.  I want to be able to structure the app like this:</p>
  
  
  
  <pre class="lang-vb prettyprint-override"><code>Sub WorkerMethod()
     'Do some work
     Trace.WriteLine("Work progress")
  
     'Do more work
     Trace.WriteLine("Another progress update")
  
     '...
  End Sub
  
  
  Sub Main()
  
     'Do any setup, like confirm the user wants to continue or whatever
  
     WorkerMethod()     
  
  End Sub
  </code></pre>
  
  <p>Note that I'm using <code>Trace</code> rather than <code>Console</code> for my output.  This is because the worker method may be called from elsewhere, or even live in a different assembly, and I want to be able to attach different trace listeners to it.  So how can I connect the console to the trace? </p>
  
  <p>I can already do it by defining a simple class (shown below) and adding an instance to the Trace's listeners collection, but I'm wondering if there's a more accepted or built in way to accomplish this:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Public Class ConsoleTrace
      Inherits Diagnostics.TraceListener
  
      Public Overloads Overrides Sub Write(ByVal message As String)
          Console.Write(message)
      End Sub
  
      Public Overloads Overrides Sub WriteLine(ByVal message As String)
          Console.WriteLine(message)
      End Sub
  End Class
  </code></pre>