fixed a bug when log file creation failed

1. handle the case when log folder creation failure
2. only set log handler after log file opened successfully