WCF Tracing Note

来源:互联网 发布:乌菲兹美术馆讲解软件 编辑:程序博客网 时间:2024/05/06 12:47

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 thepropagateActivityattribute 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。