WCF tracing FAQ

Introduction and Goal

WCF basic questions and answers

Can you explain the concept of trace listener?

What are the readymade trace events and they are available for which WCF objects ?

How can we enable tracing on the readymade tracing WCF objects?

What is the concept of tracelevel in trace listeners?

What is a service level message and transport level message?

Introduction and Goal
In this article we will look how we can trace and debug information in WCF services. There are some ready made tracelisteners provided by WCF. The base of these ready made trace listeners is .NET trace listener. So we will first understand the basic concept of trace listener and then go through the ready made tracelisteners provided by WCF. Now a days I am distributing my 400 questions and answers ebook which covers major .NET related topics like WCF,WPF,WWF,Ajax,Core .NET,SQL Server,Architecture and lot lot more. I am sure you will enjoy this ebook. http://www.questpond.com/SampleDotNetInterviewQuestionBook.zip

WCF basic questions and answers
If you are new to WCF I will recommend give one read to my WCF FAQ’s before reading this article at Part 1 :-http://www.codeproject.com/KB/aspnet/WCF.aspx . It will help you to understand WCF fundamentals so that you can understand this article much better.

Can you explain the concept of trace listener?

Figure:. For instance you can see from the figure ‘TraceListener’ how it listens to the trace object and outputs the same to UI.‘Tracelistener’ are objects that get tracing information from the trace class and they output the data to some medium. Figure .TraceListener Below is a code snippet for ‘textwritertracelistener’ and ‘eventlogtracelistener’.Tracelistener in action What are the readymade trace events and they are available for which WCF objects ? . File or a windows event log. There are three different types of ‘tracelistener’ first is the ‘defaulttracelistener’ (this outputs the data to UI). second is ‘textwritertracelistener’ (this outputs to a file) and the final one is ‘Eventlogtracelistener’ which outputs the same to a windows event log. Using ‘textwritertracelistener’ we have forwarded the trace’s to ‘ErrorLog.txt’ file and in the second snippet we have used the ‘Eventlogtracelistener’ to forward the trace’s to windows event log.

ServiceModel System.ServiceModel" switchValue="Information.diagnostics> <sources> <source name="System. WCF always serializes and deserializes information during request so it’s a good event to see the content of the request. ActivityTracing"> <listeners> <add name="log" type="System.ServiceModel. We need to also define the file and path where the file is created.NET .Log CardSpace Generates tracing information for every message that flows through the system.config’ file of the WCF service.Activation System.Runtime.You can always use the core ‘Tracelistener’ events provided by .Serialization System.Diagnostics.ServiceModel. Emits information when objects are serialized or deserialized. Collapse Copy Code <system. For the current scenario we have defined the file as ‘Traces.ServiceModel.ServiceModel’ tracing object. We need to also define the type of listeners for the ‘System. Emits trace messages related to any CardSpace identity processing that occurs within WCF context.IdentityModel System. Emits information regarding activation of the service.XmlWriterTraceListener’. Generate trace data for authentication and authorization. To enable tracing we need to enable the ‘system.IO.MessageLogging System.Diagnostics. So we add the ‘listeners’ tag with the type as ‘System. Emits messages with respect to Common Log File System (CLFS).XmlWriterTraceListener" . Assembly Name Description Logs the following :• • • • Message process Reading of configuration information Transport-level action Security requests System.diagnostics’ XML node in the ‘web.svclog’ and the folder as ‘c:\’ drive. but WCF has readymade trace listeners for the core WCF objects.ServiceModel’ listener object. How can we enable tracing on the readymade tracing WCF objects? We will enable tracing on ‘System.

The Error application is still capable of continuing its processing.WebServer" ProcessID="2660" ThreadID="8" /> <Channel/> <Computer>COMPAQ-JZP37MD0</Computer> </System> <ApplicationData></ApplicationData> </E2ETraceEvent> What is the concept of tracelevel in trace listeners? In the previous question we have specified switch value as information.config’ snippet indicates the trace type as ‘Information’.diagnostics> .com/2004/06/E2ETraceEvent"> <System xmlns="http://schemas. Trace level value is specified in ‘source’ tag in switch value. Collapse Copy Code #<E2ETraceEvent xmlns="http://schemas. In this case messages are related to communication between ActivityTracing components and the activities. Verbose Very similar to information but provides more details as compared. Collapse Copy Code <system. All In this case all messages are captured.microsoft.5625000Z" /> <Source Name="System. Trace Level Off Description Ignore all trace messages Log unexpected processing events or unhandled exceptions have Critical occurred. Indicates there is a possible problem but the application will continue Warning running. In this case messages are just milestones. Application is running smoothly only that informative message is Information recorded. Below is the list of the same.ServiceModel" /> <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" RelatedActivityID="{d11829b7-d2db-46d5-a4ac-49a37a56376e}" /> <Execution ProcessName="WebDev. For instance the below ‘web.com/2004/06/windows/eventlog/system"> <EventID>0</EventID> <Type>3</Type> <SubType Name="Transfer">0</SubType> <Level>255</Level> <TimeCreated SystemTime="2009-04-30T03:21:09.diagnostics> Now if you run the WCF service you can see a XML file created as shown below.initializeData="c:\Traces. The application will terminate immediately or shortly. This value indicates what type and level of tracing information you want to record. An unexpected processing event or exception has occurred.microsoft.svclog" /> </listeners> </source> </sources> </system.

ActivityTracing"> ... . ........ Collapse Copy Code <system.. Transport level: .... logMessagesAtServiceLevel Should service-level messages be logged..In this the messages are logged as they are ready to be encoded / decoded... All transport level.... ... Max size of the message log.. logMessagesAtTransportLevel Should transport level messages be logged.<sources> <source name="System.. Attribute logEntireMessage Description Should the entire message be logged on only the header. below is the short description about the same. Service level:-In this the messages are logged as they enter the user code or leave the user code. infrastructure messages and also reliable messaging is logged.. Number indicating how many messages should be maxMessageToLog logged. maxSizeOfMessageToLog The default value is 256Kb.serviceModel> ‘Messagelogging’ also has other attributes ........ logMalformedMessages Should malformed messages be logged.. What is a service level message and transport level message? You can log WCF message at two levels one is service level and the other is transport level...serviceModel> <diagnostics> <messageLogging logEntireMessage="true" logMalformedMessages="false" logMessagesAtServiceLevel="false" logMessagesAtTransportLevel="true" maxMessagesToLog="3000" maxSizeOfMessageToLog="10000"/> </diagnostics> </system...... You specify the message levels in the diagnostics node as shown in the below code snippet... ...ServiceModel" switchValue="Information..

Sign up to vote on this title
UsefulNot useful