added function to record the error in file by date and time