Can Log4net have multiple appenders write to the same file?

前端 未结 2 1825
伪装坚强ぢ
伪装坚强ぢ 2020-12-09 09:16

I\'m using a RollingFileAppender to log some info to a file with a conversionPattern (in the web.config) that looks like this for the header of each log section:

<         


        
2条回答
  •  情深已故
    2020-12-09 09:54

    Yes you can have two log4net appenders that append (write) to the same log file.

    You need to place the following line in each of your Appenders:

    
    

    This will make log4net use a minimal locking model that allows multiple processes to write to the same file.

    Here's an example XML that uses two appenders writing to the same log file:

    
    
      
      
      
      
      
      
      
      
      
      
      
      
        
      
      
    
    
      
      
      
      
      
      
      
      
      
      
      
        
      
    
    
      
      
      
    
    

    This can be found in the Apache documentation here: Apache Log4Net Docs Just search on this page for 'same file'.

    Hope this helps.

提交回复
热议问题