Adding Error Logs File Writing and Cleaning Code