Close log file and config file properly