Correct way of using log4net (logger naming)

前端 未结 4 886
感动是毒
感动是毒 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:43

    My Answer might be coming late, but I think it can help newbie. You shall not see logs executed unless the changes are made as below.

    2 Files have to be changes when you implement Log4net.


    1. Add Reference of log4net.dll in the project.
    2. app.config
    3. Class file where you will implement Logs.

    Inside [app.config] :

    First, under 'configSections', you need to add below piece of code;

    Then, under 'configuration' block, you need to write below piece of code.(This piece of code is customised as per my need , but it works like charm.)

    
        
          
          
        
    
        
          
          
          
          
          
          
    
          
            
          
        
    
    

    Inside Calling Class :

    Inside the class where you are going to use this log4net, you need to declare below piece of code.

     ILog log = LogManager.GetLogger("log");
    

    Now, you are ready call log wherever you want in that same class. Below is one of the method you can call while doing operations.

    log.Error("message");
    

提交回复
热议问题