Should log file streams be opened/closed on each write or kept open during a desktop application's lifetime?

前端 未结 13 1231
小蘑菇
小蘑菇 2020-12-04 19:52

Should log classes open/close a log file stream on each write to the log file or should it keep the log file stream open throughout the application\'s lifetime until all log

13条回答
  •  广开言路
    2020-12-04 19:55

    It's generally better to keep them open.

    If you're concerned about being able to read them from another process, you need make sure that the share mode you use to open/create them allows others to read them (but not write to them, obviously).

    If you're worried about losing data in the event of a crash, you should periodically flush/commit their buffers.

提交回复
热议问题