Console.SetError sets the Error property to the specified TextWriter object.
Imports System.IO
Imports System.Reflection
Module RedirectStdErr
Public Sub Main()
Dim appStart As Date = Date.Now
Dim fn As String = "c:\" & appStart.ToString("yyyyMMddHHmm") & ".log"
Dim errStream As New StreamWriter(fn)
Dim appName As String = Assembly.GetExecutingAssembly().Location
appName = Mid(appName, InStrRev(appName, "\") + 1)
Console.SetError(errStream)
Console.Error.WriteLine("Error Log for Application {0}", appName)
Console.Error.WriteLine("Application started at {0}.", appStart)
Console.Error.Close()
End Sub
End Module
Related examples in the same category