Introduction: Tracing in .NET Framework 4.0 and how it is used in WCF Services.
In this article, we will look at how we can trace and debug information in WCF services.Windows Communication Foundation (WCF) provides application instrumentation and diagnostic data for fault monitoring and analysis. Instead of using debugger, You can use tracing to understand how an application is behaving,
WCF Tracing can track all the events or only specified events in the program. Tracing is built upon the System.Diagnostics namespace of the .NET Framework.
WCF outputs the following data for diagnostic tracing:
- Traces for process milestones across all components of the applications, such as operation calls, code exceptions, warnings and other significant processing events."
- Windows error events when the tracing feature malfunctions.
The important thing about tracing is:-
It is turned off by default, so it needs to be enable for starting tracing.
There are two ways to enable tracing. These are followings:-
- One is through code.
- Second is, through config file.
Enabling tracing in config file is good method since we can easily turn it on and off as required. When debugging is no longer required we should turn tracing enable off.
Enabling Tracing :
The following code will enable tracing through configuration file:
<system.diagnostics>
<trace
autoflush="true"
/>
<sources>
<source
name="System.ServiceModel"
switchValue="All">
<listeners>
<add
name="TraceListeners"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData=
"c:\Log\trace.svclog"/>
</listeners>
</source>
</sources>
</system.diagnostics>
Join the conversation! Your thoughts help the community grow.