The following configuration shows how to enable WCF tracing. Specifically, it shows how to:

  • Log messages at both the service and transport level, to inspect the raw XML on the wire.

  • Enable WCF exception tracing, to capture errors in message security header processing.

  • Turn on digest logging, which allows inspection of canonicalized digests to help understand signature verification exceptions.

  • Enable activity tracing, to help correlate messages and identify at what stage an exception is thrown.

For more information, see WIF Tracing.

  Copy Code
<configuration>
  <system.serviceModel>
	<diagnostics>
	<messageLogging maxMessagesToLog="30000"
			logEntireMessage="true"
			logMessagesAtServiceLevel="true"
			logMalformedMessages="true"
			logMessagesAtTransportLevel="true">
	</messageLogging>
	</diagnostics>
  </system.serviceModel>
  <system.diagnostics>
	<sources>
	<!-- This section turns on digest logging, note that for this to work correctly,
		 you need to add the following to machine.config:
			<system.serviceModel>
				<machineSettings enableLoggingKnownPii="true" />
			</system.serviceModel>
		 Search for 'DigestTrace' in the trace viewer to view the digest logs.
	-->
	<source name="System.IdentityModel" switchValue="Verbose" logKnownPii="true">
		<listeners>
		<add name="xml" />
		</listeners>
	</source>
	<!-- Log all messages in the 'Messages' tab of SvcTraceViewer. -->
	<source name="System.ServiceModel.MessageLogging">
		<listeners>
		<add name="xml" />
		</listeners>
	</source>
	<!-- ActivityTracing and propogateActivity are used to flesh out the 'Activities' tab in
		 SvcTraceViewer to aid debugging. -->
	<source name="System.ServiceModel" switchValue="Error, ActivityTracing" propagateActivity="true">
		<listeners>
		<add name="xml" />
		</listeners>
	</source>
	<!-- This records Microsoft.IdentityModel generated traces, including exceptions thrown
		 from the framework. -->
	<source name="Microsoft.IdentityModel" switchValue="Warning">
		<listeners>
		<add name="xml" />
		</listeners>
	</source>
	</sources>
	<sharedListeners>
	<add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="trace.e2e" />
	</sharedListeners>
	<trace autoflush="true" />
  </system.diagnostics>
</configuration>