【发布时间】:2011-04-27 14:01:41
【问题描述】:
我想编写将所有数据写入 SQL Server DB 的 CustomTraceListener。 这是它的存根:
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 作为图片发布 - 似乎 SO 编辑器不允许在帖子中使用一些 xml 关键字):
但根据标准 XmlWriterTraceListener 我应该得到这个:
如何配置 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"/>
【问题讨论】:
-
您找到解决问题的方法了吗?
-
很遗憾没有。我使用标准的 XmlWriterTraceListener 作为存根有一段时间了。
标签: wcf soap trace tracelistener