All pastes #161472 Raw Edit

Marcelo

public text v1 · immutable
·published 2006-09-05 13:43 UTC
rendered paste body
Imports System
Imports System.IO
   
Public Class Log
   
  Public Delegate Sub Writer(ByVal msg As String)
  Private myWriter As Writer
   
  Public Sub New(ByVal writeMethod As Writer)
    myWriter = writeMethod
  End Sub
   
  Public Sub Write(ByVal msg As String)
    myWriter(msg)
  End Sub
   
End Class
   
Friend Class Test
   
  Public Shared Sub Write(ByVal msg As String)
   
    Dim file As New FileStream("debug.log", _
                               FileMode.OpenOrCreate, _
                               FileAccess.Write)
   
    Dim stream As New StreamWriter(file)
   
    'Write date/time and message
    stream.Write("{0} - {1}", DateTime.Now, msg)
   
    'Close the stream (and the file, too)
    stream.Close( )
   
  End Sub
   
  Public Shared Sub Main( )
    Dim debugLog As New Log(AddressOf Write)
    debugLog.Write("Welcome to Visual Basic!")
  End Sub
   
End Class