[英]WCF Diagnostics Message Logging With Unique Id
I'm logging messages for WCF web service using System.Diagnostics
System.ServiceModel.MessageLogging
with configuration below. 我正在使用
System.Diagnostics
System.ServiceModel.MessageLogging
和以下配置记录有关WCF Web服务的消息。 And I extended TraceListener
class as: 我将
TraceListener
类扩展为:
public class FormattedTraceListener : TraceListener
{
static readonly Logger logger = new Logger();
public FormattedTraceListener()
: base(string.Empty)
{
}
public override void TraceData(TraceEventCache eventCache,String source,TraceEventType eventType,**Int32 id,**Object data)
{
//....
<system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging" >
<listeners>
<add name="pretty" />
<remove name="Default"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name="pretty" lockItem="true" type="LoggingTest.FormattedXmlWriterTraceListener,LoggingTest" />
</sharedListeners>
<trace autoflush="true" indentsize="4">
</trace>
</system.diagnostics>
....
<diagnostics >
<messageLogging
logEntireMessage="true"
logMalformedMessages="false"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="false"
maxMessagesToLog="-1"
maxSizeOfMessageToLog="134217728">
<filters >
<add xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">/s:Envelope</add>
<add xmlns:s="http://www.w3.org/2003/05/soap-envelope">/s:Envelope</add>
</filters>
</messageLogging>
<endToEndTracing propagateActivity="true" activityTracing="true" messageFlowTracing="true" />
</diagnostics>
</system.serviceModel>
TraceData
method fired twice (for request and response) for each service call. 对于每个服务调用,
TraceData
方法均触发两次(用于请求和响应)。 However, when method is hit, the id
parameter is always 0. 但是,当单击method时,
id
参数始终为0。
I need a unique id in logging text to match request and response log. 我需要在日志记录文本中使用唯一的ID来匹配请求和响应日志。 How can I specify that?
我该如何指定?
Your approach is not right. 您的方法不正确。 The TraceData(int id) field is not a unique id for the WCF request.
TraceData(int id)字段不是WCF请求的唯一ID。 It's the application defined code for the event type.
它是事件类型的应用程序定义的代码。
Just use the standard WCF trace classes and view correlated traces . 只需使用标准WCF跟踪类并查看相关跟踪即可 。 If I understand what you are trying to accomplish in matching up request to response, the default behavior already meets your requirements.
如果我了解您在匹配请求和响应中要完成的工作,则默认行为已经满足您的要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.