I see that you made some changes in the WriteLog2 UDF. DUDF's are ready for use and do not need to be modified. All you need to do is include them in the code or call them from your code. See the example below on how to use the WriteLog2 UDF.
This code:
 Code:
Break on

$file = "c:\logfile.txt"

$rc = WriteLog2($file, "This is a test")
$rc = WriteLog2($file, "This is a test",0)
$rc = WriteLog2($file, "This is a test",1)


;FUNCTION         WriteLog2()
;
;AUTHOR           Howard A. Bullock (hbullock@tycoelectronics.com)
;
;ACTION           Generic logging facility for scripts. Appends log entry to a file with an optional TimeStamp.
;
;SYNTAX           WriteLog2($File, $text, [0|1])
;
;PARAMETERS       $File (Required) -  String value
;                 $text (Required) -  String value
;                 $TimeStamp (Optional) Default(0) no TimeStamp (1 or 0)
;
;
;REMARKS          This function writes (appends) an optionally time stamped log entry to the file defined in function.
;                 This function searches for the first unused file handle, open the file, and write the entry. T he file handle
;                 is then closed. When the function is unable to perform its it write the error is displayed&nbs p;in a message box.
;
;RETURNS          Nothing
;
;DEPENDENCIES     None
;
;EXAMPLES         WriteLog2("junk.txt","This is a test")
;                 WriteLog2("junk.txt","This is a test",0)
;                 WriteLog2("junk.txt","This is a test",1)
;
;
Function WriteLog2($File, $Text, optional $TimeStamp)
	;ACTION: Writes text to a specified log file.
	Dim $RC, $File, $text, $FH, $TimeStamp
	$FH = 1
	$RC = Open($FH, $File, 5)
	While $RC = -3
		$FH = $FH + 1
		$RC = Open($FH, $File, 5)
	Loop
	Select
		Case $RC = 0
			If ($TimeStamp = 1)
				$TimeStamp = @Date + " " + @Time + " - "
			Else
				$TimeStamp = ""
			EndIf
			$RC = WriteLine($FH, $TimeStamp + $Text + @CRLF)
			$RC = Close($FH)
		Case $RC = -2
			$text = "WriteLog2: Invalid file handle ($FH) specified when trying to Open $File."
			$RC = MessageBox($text, "Script Error", 48)
		Case $RC = -1
			$text = "WriteLog2: Invalid file name ($File) specified for log file."
			$RC = MessageBox($text, "Script Error", 48)
		Case $RC = > 0
			$text = "System Error($RC) while attempting to open log file ($File)."
			$RC = MessageBox($text, "Script Error", 48)
	EndSelect
EndFunction


will give you:
 Quote:

This is a test
This is a test
2011/07/07 11:20:05 - This is a test
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.