WCF Tracing Note

http://msdn.microsoft.com/en-us/library/aa751917.aspx

There are four components to WCF Diagnostics: Eventing,Tracing, which includes Activity Tracing, and Message Logging.

            -Activities

                        -“areprocessing units that help the user narrow down the scope of a failure. Errorsthat occur in the same activity are directly related.”

                        -Code:

                        <sourcename="System.ServiceModel"switchValue="Verbose,ActivityTracing">

            -Transfer:“Transfers between activities represent causal relationshipsbetween events inthe related activities within endpoints. Two activities are related with transfers when control flows between these activities, e.g., a method callcrossing activity boundaries.” In plain words, we can see transfers likerelationships between activities.

            -Propagation

                        -Propagation provides the user with direct correlation of error traces for the same unit of processingacross application endpoints,even across application domains. This is done through propagation of the activity ID in the message headers.

                        -e.g:Errors emitted at different endpoints for the same unit of processing (forexample, a request) are grouped in the same activity,

                        -Activitypropagation is a configurable capability that causes WCF to add a header tooutbound messages, which includes the activity ID on the TLS.

                       

 **Activities,transfers, and propagation allow you to perform error correlation. In this way,you can find the root cause of an error more quickly. 

 **we can correlateactivities through transfers (within the same endpoint) and propagation (acrossendpoints)

 **If thepropagateActivity attribute isset to true on both the client and service, theambient activity in the operation scope of the service is set by WCF.

 

http://msdn.microsoft.com/en-us/library/aa738759.aspx

Emitting User-Code Traces

            -Code:

                        -Creatinga Trace Source:

                        TraceSource ts = new TraceSource("myUserTraceSource");

                        -CreatingActivities (Activities are logical unit of processing)

                        GuidoldID = Trace.CorrelationManager.ActivityId;

                        GuidtraceID = Guid.NewGuid();

                        ts.TraceTransfer(0,"transfer", traceID);

                        Trace.CorrelationManager.ActivityId= traceID; // Trace is static

                        ts.TraceEvent(TraceEventType.Start,0, "Add request");

                        -EmittingTraces within a User Activity

                        doublevalue1 = 100.00D;

                        doublevalue2 = 15.99D;

                        ts.TraceInformation("Clientsends message to Add " + value1 + ", " + value2);

                        doubleresult = client.Add(value1, value2);

                        ts.TraceInformation("Clientreceives Add response '" + result + "'");

                        -Stoppingthe Activities

                                    -Tostop the activities,transfer back to the old activity, stop the current activity id, and reset the old activity id in scope.

                        ts.TraceTransfer(0,"transfer", oldID);

                        ts.TraceEvent(TraceEventType.Stop,0, "Add request");

                        Trace.CorrelationManager.ActivityId= oldID;


 http://blog.csdn.net/quanben/article/details/5271298

端到端跟踪

活动(Activities)是WCF端到端跟踪中基本信息单元。 
活动不是对象,而是WCF进行处理活动的一些节点。活动一般可以解释为:当X正在发生时,跟踪就产生。 
为了实现端到端跟踪,在client和service的source的propagateActivity属性均需设置为true,这样一个跟踪就可以产生一个转移跟踪(Trace Transfer)。 
用Guid.NewGuid()创建一个Guid对象 
Trace.CorrelationManager.ActivityId用来设置当前活动的GUID。 
ts.TraceTransfer(int eventId, string message, Guid relatedActivityId)用来发生转移,relatedActivityId为转入时为新的GUID,转回时为原GUID。 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值