use logger to trace exception , close stream in finally