While doing some tutorials on Linq on .Net 3.0, I found the sample have another simpler way to achieve that. Here are the steps:
1) Create a windows application
2) Design a simple GUI. Button represents you business logic and multiline textbox means the trace information.
3) Set the StreamWriter to the Console output, re-capture it with TextWriter will do.
Public Class Form1
Private ReadOnly _OutputStreamWriter As StreamWriter = New StreamWriter(New MemoryStream())
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Capture console output
Dim writer As StreamWriter = _OutputStreamWriter
Dim oldConsoleOut As TextWriter = Console.Out
Dim stream As MemoryStream = CType(writer.BaseStream, MemoryStream)
' set to result pane
TextBox1.Text += writer.Encoding.GetString(stream.ToArray())
Private Sub DoSomething()
4) Here's the final result: