The log writter should only be closed if logging is enabled.