Adding basic log file support.
Adding logging of exceptions to log file.
Fixing file handle close call.