instead of doing this complex error reporting UDF, why don't you just display the errors after each of the functions and commands.
if you want errorlog udf, something simple as the one below should do exactly what you already do:
Code:

function LogErrors()
if @error
$errorString = @wksta + "--> " + @serror + " (" + @error + ")"
$=RedirectOutput($ErrorFile)
$errorString ?
endif
endfunction

_________________________
!

download KiXnet