Write exceptions to a log file if in debug mode.