UserRename() will return an @error value

you can either use writeline() to write to an open file or...

something like this.

shell '%comspec% /c echo @error:@serror >> error.txt'

i think that there are even some Log Error type UDF's available.