What are the best practices for including logging using log4net?

后端 未结 9 987
夕颜
夕颜 2021-02-07 04:04

I have been told to add “logging” to my code using log4net, the problem is no one can travel in time and see what real world problems the logging will need to be used to solve.<

9条回答
  •  无人及你
    2021-02-07 04:51

    My favorite source of information for this kind of question is Release It - a book from the Pragmatic guys. Highly highly recommended.

    Their basic point in regards to your question is that logging should be geared toward what is needed at the operational level. Operations guys are most concerned with exceptional things where the site may be going down (i.e. connection pool is full, connection to a server is down, etc.) Make sure the messages are self-explanatory and exceedingly clear as to what the problem is, and if applicable what the fix is. Write the messages for human consumption.

    I see little point in function entry/exit style logs. Stack traces for top-level caught exceptions are useful, logging around areas where system crash can happen (i.e. full connection pool) is useful, as is logging around areas where the system crashed before.

提交回复
热议问题