070-483 Free Dumps Study Materials
Question 4: You are developing an application that includes a Windows Communication Foundation (WCF)
service. The service includes a custom TraceSource object named ts and a method named DoWork.
The application must meet the following requirements:
* Collect trace information when the DoWork() method executes.
* Group all traces for a single execution of the DoWork() method as an activity that can be viewed in
the WCF Service Trace Viewer Tool.
You need to ensure that the application meets the requirements.
How should you complete the relevant code? (To answer, select the correct code segment from each
drop-down list in the answer area.)
Correct Answer:Explanation
Activities are logical unit of processing. You can create one activity for each major processing unit in
which you want traces to be grouped together. For example, you can create one activity for each
request to the service. To do so, perform the following steps.
Save the activity ID in scope.
Create a new activity ID.
Transfer from the activity in scope to the new one, set the new activity in scope and emit a start trace
for that activity.
The following code demonstrates how to do this.
Guid oldID = Trace.CorrelationManager.ActivityId;
Guid traceID = Guid.NewGuid();
ts.TraceTransfer(0, "transfer", traceID);
Trace.CorrelationManager.ActivityId = traceID; // Trace is static
ts.TraceEvent(TraceEventType.Start, 0, "Add request");
Reference: Emitting User-Code Traces
https://msdn.microsoft.com/en-us/library/aa738759(v=vs.110).aspx