Imports System.Runtime.InteropServices
Imports System.Text
Public Class MyConsoleApp
<DllImport("coredll")> _
Public Shared Function GetStdioPathW( _
ByVal id As Integer, _
ByVal originalPath As StringBuilder, _
ByRef pathLength As Integer _
) As Integer
End Function
<DllImport("coredll")> _
Public Shared Function SetStdioPathW( _
ByVal id As Integer, _
ByVal newPath As String _
) As Integer
End Function
Shared Sub Main()
Dim STDOUT As Integer = 1
' Retrieve the existing path for standard output
Dim originalPath As New StringBuilder
Dim pathLength As Integer = 256
GetStdioPathW(STDOUT, originalPath, pathLength)
' Set standard output to redirecto to a
' file in MyLogFile.txt
Dim myLogFile As String = "\MyLogFile.txt"
SetStdioPathW(STDOUT, myLogFile)
' Write to standard output
Console.WriteLine("Hello World 1")
Console.WriteLine("Hello World 2")
Console.WriteLine("Hello World 3")