Console.SetError sets the Error property to the specified TextWriter object. : Console « Development « VB.Net






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

1.Do calculation in Console.WriteLineDo calculation in Console.WriteLine
2.Output Format for IntegerOutput Format for Integer
3.Console OutputConsole Output
4.Console Read and Compare IntegerConsole Read and Compare Integer
5.Redirect console to a file
6.Display 4 mandatory and 3 optional arguments using the Console.WriteLine method.
7.Display 4 mandatory and 3 optional arguments using the Console.Write method.
8.Use Console.Write method.
9.ConsoleColor Enumeration
10.ConsoleKey Enumeration
11.ConsoleKeyInfo Structure
12.ConsoleSpecialKey Enumeration
13.Console Class
14.Console.BackgroundColor Property gets or sets the background color of the console.
15.Console.Beep Method plays the sound of a beep through the console speaker.
16.Console.BufferHeight Property gets or sets the height of the buffer area.
17.Console.CancelKeyPress Event occurs when Control key (CTRL) and C are pressed simultaneously (CTRL+C).
18.Console.Clear Method clears the console buffer and corresponding console window of display information.
19.Console.CursorSize Property gets or sets the height of the cursor within a character cell.
20.Console.CursorVisible Property tells indicating whether the cursor is visible.
21.Console.Error Property gets the standard error output stream.
22.Console.In Property gets the standard input stream.
23.Console.KeyAvailable tells whether a key press is available in the input stream.
24.Console.Out Property gets the standard output stream.
25.Console.ReadKey (Boolean) gets next character or function key pressed
26.Console.ReadKey gets next character or function key pressed by the user.
27.Console.ReadLine reads the next line of characters from the standard input stream.
28.Console.SetOut Method sets the Out property to the specified TextWriter object.
29.Console.SetWindowSize Method sets the height and width of the console window
30.Console.Title Property gets or sets the title to display in the console title bar.
31.Console.WindowLeft Property gets or sets the leftmost position of the console window area relative to the screen
32.Console.Write Method (Boolean) writes the text representation of the Boolean value to the standard output stream.
33.Console.WriteLine Standard Numeric Format Strings: C2