Correct way of using log4net (logger naming)

前端 未结 4 887
感动是毒
感动是毒 2020-12-22 21:15

There are two ways of configuring and using log4net. First one is when I can configure my own appender and associated logger:



&         


        
4条回答
  •  忘掉有多难
    2020-12-22 21:27

    Instead of naming my invoking class, I started using the following:

    private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    

    In this way, I can use the same line of code in every class that uses log4net without having to remember to change code when I copy and paste. Alternatively, i could create a logging class, and have every other class inherit from my logging class.

提交回复
热议问题