What are the best practices for including logging using log4net?

后端 未结 9 1109
夕颜
夕颜 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:32

    In general with logging I add logging in the following order:

    1. Function Enter/Exit
    2. Major logic steps inside of a function
    3. Verbose logging for all intermediate calculations

    Obviously I rarely get to the last one, the first one is trivial to do if you roll your own wrapper for log4net and use the disposing pattern, and possibly a little reflection magic.

    The 2nd one is done generally during acceptance/integration and regression testing as major logic flow and problem areas are identified. Adding logging at this stage is also fairly minimal as you know in general where you need to add it as you are debugging and testing.

    The 3rd is generally (for me anyways) only done in sections of code that experience regressions, or are particularly important.

    I have implemented a basic wrapper object for log4net which provides me direct logging capabilities as well as a context object which can be used with IDisposable to wrap "enter/exit" logic in a nice convient package.

提交回复
热议问题