How can I enable WCF logging so that it writes to a Database?

后端 未结 3 664
梦谈多话
梦谈多话 2021-01-12 03:59

I\'d like to be able to log message information in a database, and I\'m trying to decide how best to do that. Is it possible to configure the WCF logging mechanisms to write

3条回答
  •  -上瘾入骨i
    2021-01-12 04:28

    You need to have two things:

    • a proper config to enable .NET tracing
    • a trace listener to capture the trace messages and store them in a database

    For #1:
    You need to turn on tracing in WCF first - you need an entry in that enables tracing:

    
       
          
        
    
    

    Next, you need to configure .NET tracing as such:

    
       
          
             
                
             
          
          
             
                 
             
          
       
       
           
       
    
    

    Here, instead of the WebTraceListener, or other pre-defined listeners, you can also plug in your own database-oriented trace listener.

    For #2:
    You can - of course - write your own SqlTraceListener - or you can use one of the many ready-made solutions out there, for instance this one here (download the code from Codeplex).

提交回复
热议问题