Logging multiple instance application best practice?

后端 未结 2 637
你的背包
你的背包 2021-02-19 01:07

I finally tried log4net for my WPF desktop application.

I\'m struggling with the fact that RollingFileAppender has no built in support for multiple instance application

2条回答
  •  猫巷女王i
    2021-02-19 01:28

    It's not a good idea to use multiple RollingFileAppender instances from different processes writing to the same file since the RollingFileAppender isn't designed for that scenario.

    You have a couple of choices here:

    Multiple FileAppender with minimal locking

    Use multiple FileAppender instances pointing at the same file and configured with minimal locking. This will allow concurrent write operations from multiple processes:

    
        
        
        
        
            
        
    
    

    Multiple EventLogAppender

    Use multiple EventLogAppender instances that write to a shared Windows event source:

    
        
        
            
        
    
    

    Of course you could also send the log to a database or to a remote component running in a different process or even a different machine but these choices require more infrastructure to be setup so it may be overkill for your scenario.

    Related resources:

    • log4net Config Examples

提交回复
热议问题