Since we don't flush the messages to file immediately to avoid slowdowns, sometimes the application is closed before all the messages are written to the log.
This includes flushing the log when stopping the emulation, and tries to close the log file when closing the application. (It might need some more work to close it in all cases).
Also, some redundancy in logging.c and x86seg.c has been removed.