Improve LogToFile functionality