Automatically log System.diagnostics.trace messages to an Nlog target

后端 未结 3 1107
眼角桃花
眼角桃花 2021-01-11 09:25

Say you have C# trace messages all over an application. Something like:

Trace.TraceInformation(\"Service Started\"); 

How do you aut

3条回答
  •  耶瑟儿~
    2021-01-11 10:15

    You can use NLog's NLogTraceListener.

    For completeness, here is the System.Diagnostics configuration (from the link above) to specify the NLogTraceListener:

    
    
      
        
          
            
              
            
          
          
            
              
            
          
        
        
          
        
      
    
    

    You also need to configure NLog to tell it how to write the information once it moves from the System.Diagnostics.Trace to NLog:

    
      
        
      
    
      
        
      
    
    

提交回复
热议问题