Added file writing to logfile.