Logging in multiple files using NLog

前端 未结 6 2029
长情又很酷
长情又很酷 2020-12-08 00:28

I am using NLog for logging purpose.

My code is as follows:



        
6条回答
  •  感情败类
    2020-12-08 01:11

    If you want to still be able to use the convenient GetCurrentClassLogger method, you can filter the log messages to go to the correct target by using the namespaces in your project as a filter.

    Say you have namespaces which start with fooA and namespaces which start with fooB. Then your NLog.config file would look like this:

    
       
       
    
    
    
        
        
    
    

    And in your code, you just add a logger in every class you want to log:

    private static Logger logger = LogManager.GetCurrentClassLogger();
    

    As long as your namespaces are consistent, the log messages will filter to the correct file and you get a nice little class tag in your log messages to tell you where the log event occurred.

提交回复
热议问题