【发布时间】:2011-05-27 18:06:15
【问题描述】:
我有一个具有以下合同的 WCF 服务:
[ServiceContract(Namespace="http://myNamespace.org/")]
public interface IMyService
{
[OperationContract]
string Invert(string s);
[OperationContract]
string ToUpper(string s);
}
客户端调用Invert 和ToUpper 这两种方法。想象一下我想使用消息记录,但我感兴趣的唯一方法是ToUpper,因为另一种方法被大量使用并且记录所有消息会破坏日志;)
Here,我阅读了如何过滤写入日志的消息。但是我一定是做错了什么,因为我的日志仍然是空的......我的配置看起来像这样
<system.serviceModel>
...
<diagnostics>
<messageLogging logEntireMessage="true" logMessagesAtServiceLevel="false" logMalformedMessages="true" logMessagesAtTransportLevel="true">
<filters>
<add xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">/soap:Envelope/soap:Header/a:Action[starts-with(text(),'http://myNamespace.org/IMyService/ToUpper')]</add>
</filters>
</messageLogging>
</diagnostics>
</system.serviceModel>
<system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="ServiceModelTraceListener" />
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="LogServer.svclog" type="System.Diagnostics.XmlWriterTraceListener" name="ServiceModelTraceListener" />
</sharedListeners>
<trace autoflush="true" />
</system.diagnostics>
如果我应用此过滤器,日志中不会有一条消息... 那么对于上面的链接示例,我做错了什么?
如果没有过滤器,默认消息的 xml 跟踪(使用字符串参数 hello 调用的方法 ToUpper)如下所示:
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<EventID>0</EventID>
<Type>3</Type>
<SubType Name="Information">0</SubType>
<Level>8</Level>
<TimeCreated SystemTime="2011-05-27T17:53:53.9908714Z" />
<Source Name="System.ServiceModel.MessageLogging" />
<Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
<Execution ProcessName="WcfLoggingTest.Host.vshost" ProcessID="4324" ThreadID="12" />
<Channel />
<Computer>MY-Machine</Computer>
</System>
<ApplicationData>
<TraceData>
<DataItem>
<MessageLogTraceRecord Time="2011-05-27T19:53:53.9908714+02:00" Source="TransportReceive" Type="System.ServiceModel.Channels.BufferedMessage" xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace">
<HttpRequest>
<Method>POST</Method>
<QueryString></QueryString>
<WebHeaders>
<VsDebuggerCausalityData>uIDPozEtlPQCjkhCodYdPWh6joUAAAAAamILDP7v3kG5sY6zKsB7HPPiLBWr+AVGmfFDQbk8GYAACQAA</VsDebuggerCausalityData>
<SOAPAction>"http://myNamespace.org/IMyService/ToUpper"</SOAPAction>
<Content-Length>157</Content-Length>
<Content-Type>text/xml; charset=utf-8</Content-Type>
<Accept-Encoding>gzip, deflate</Accept-Encoding>
<Expect>100-continue</Expect>
<Host>localhost:8731</Host>
</WebHeaders>
</HttpRequest>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://localhost:8731/Design_Time_Addresses/MyService/</To>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://myNamespace.org/IMyService/ToUpper</Action>
</s:Header>
<s:Body>
<ToUpper xmlns="http://myNamespace.org/">
<s>hello</s>
</ToUpper>
</s:Body>
</s:Envelope>
</MessageLogTraceRecord>
</DataItem>
</TraceData>
</ApplicationData>
</E2ETraceEvent>
更新: 对于每个对解决方案感兴趣的人,我终于在 jasso 的帮助下完成了工作,谢谢:
<add xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">/soap:Envelope/soap:Header/a:Action[starts-with(text(),'http://myNamespace.org/IMyService/ToUpper')]</add>
然后我编辑了我的界面并添加了方法Method1 直到Method3。我的目标是记录除与Method1 和Method3 相关的消息之外的所有内容。我使用以下过滤器做到了这一点:
<add xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">/soap:Envelope/soap:Header/a:Action[starts-with(text(),'http://myNamespace.org/IMyService/Method1')=false() and starts-with(text(),'http://myNamespace.org/IMyService/Method3')=false()]</add>
这样,只记录与Invert、ToUpper 和Method2 相关的消息。
使用两个单独的过滤器来处理这个问题可能是一种更简洁的方法,但目前我对此非常满意。
【问题讨论】:
标签: wcf logging xpath filter message