Step 1. Configuring WCF to emit tracing information/Define Trace Source
We have the following options:
- System.ServiceModel
- System.ServiceModel.MessageLogging
- System.ServiceModel.IdentityModel
- System.ServiceModel.Activation
- System.Runtime.Serialization
- System.IO.Log
- Cardspace
In configuration file, we will define a source to enable this configuration as follows:
Step 2. Setting Tracing Level
We have the following available options, we need to set this tracing level to available options other than default “Off”:
- Off
- Critical
- Error
- Warning
- Information
- Verbose
- ActivityTracing
- All
switchValue=”Information”>
Step 3. Configuring a trace listener
For configuring a trace listener, we will add following to config file.
<add name=”messages”
type=”System.Diagnostics.XmlWriterTraceListener”
initializeData=”d:logsmessages.svclog” />
</listeners>
Step 4. Enabling message logging
<diagnostics>
<messageLogging
logEntireMessage=”true”
logMalformedMessages=”false”
logMessagesAtServiceLevel=”true”
logMessagesAtTransportLevel=”false”
maxMessagesToLog=”3000″
maxSizeOfMessageToLog=”2000″/>
</diagnostics>
</system.serviceModel>
logEntireMessage: By default, only the message header is logged but if we set it to true, entire message including message header as well as body will be logged.
logMalformedMessages: this option log messages those are rejected by WCF stack at any stage are known as malformed messages.
logMessagesAtServiceLevel: messages those are about to enter or leave user code.
logMessagesAtTransportLevel: messages those are about to encode or decode.
maxMessagesToLog: maximum quota for messages. Default value is 10000.
maxSizeOfMessageToLog: message size in bytes.
Putting all this together, configuration file will appear like this.
Note: In this case, information will be buffered and not published to file automatically, So, we can set the autoflush property of the trace under sources as follows:
Other WCF and related Tutorials for Beginners:
- 3 techniques for WCF Instance Management
- WCF Contracts Simplified ( Service Contract | Data Contract | MessageContract Vs DataContract)
- What is a Known Type?
- WCF Hosting (Console | Windows Service | IIS | WAS)
- 3 simple steps to create your first ASP.NET Web API service
- Free Practical guide to WCF RESTful Service
- What’s New in WCF 4.5
- Building you first ASP.NET MVC application with Entity Framework
Top 10 Interview Questions and Answers Series:
- Top 10 WCF Interview Questions
- Comprehensive Series of WCF Interview Questions
- Top 10 HTML5 Interview Questions
- Top 10 ASP.NET Interview Questions
- Comprehensive Series of ASP.NET Interview Questions
- Top 10 ASP.NET MVC Interview Questions
- Top 10 ASP.NET Web API Interview Questions
- Top 10 ASP.NET AJAX Interview Questions
It seems to me that one also needs to make sure the identity that the AppPool executes under must have write permisisons to the log file location.
where to put this? client app or wcf app?
Dear, put this on wcf service configuration file.
Good article
Thanks, this certainly helps alot. 🙂