2011-04-27 72 views
0

我想編寫將所有數據寫入SQL Server數據庫的CustomTraceListener。 這裏的存根它:使用CustomTraceListener獲取MessageLoggingTraceRecords時,SOAP消息爲空

public class SqlTraceListener : TraceListener 
{ 
    public SqlTraceListener() 
     : base() 
    { } 

    public SqlTraceListener(String name) 
     : base(name) 
    { } 

    protected override string[] GetSupportedAttributes() 
    { 
     List<string> attributes = new List<string>(); 
     attributes.Add("connectionString"); 
     attributes.Add("actionFilter"); 
     attributes.Add("hostFilter"); 
     return base.GetSupportedAttributes(); 
    } 

    public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data) 
    { }//Other empty methods... 

} 

在重寫的方法TRACEDATA我要趕發到我的WCF服務的SOAP消息。但是,當我檢查什麼是「數據」參數我得到這個:(對不起張貼XML作爲圖片 - 它似乎很編輯器不允許在帖子一些XML關鍵字)

enter image description here 但根據標準XmlWriterTraceListener我應該得到這樣的:

enter image description here

如何配置的TraceListener不是消除SOAP消息? 我的配置是在這裏:

<system.diagnostics> 
<sources> 
    <source name="System.ServiceModel.MessageLogging"> 
    <listeners> 
     <add name="xml"/> 
     <add name="sql"/> 
    </listeners> 
    </source> 
</sources> 
<sharedListeners> 
    <add initializeData="C:\logs\StockPriceService.svclog" type="System.Diagnostics.XmlWriterTraceListener" name="xml"/> 
    <add type="SqlTraceListener.SqlTraceListener, SqlTraceListener" name="sql"/> 
</sharedListeners> 
<trace autoflush="true"/> 

+0

您是否找到解決問題的方法? – lakai 2011-08-09 05:48:40

+1

不幸的是沒有。我使用標準的XmlWriterTraceListener作爲存根一段時間。 – Dima 2011-08-09 07:56:07

回答