WCF Logging
Tracing/Listeners
You can use standard tracing/listeners, although it's two-step
- Add a normal system.diagnostics section
- In system.serviceModel, add a diagnostics/ messageLogging section
- Svclog xml files are readable with svcTraceViewer.exe
system.diagnostics
<system.diagnostics>
<sources>
<!-- sources are assembly name -->
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<!-- ActivityTracing is end to end tracing -->
<listeners>
<!-- specify type or sharedListener-->
<add name="xml" />
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="xml" />
</listeners>
</source>
</sources>
<!-- using listeners by name -->
<sharedListeners>
<add name="xml"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="C:\log\Trace.svclog" />
</sharedListeners>
<!-- flush after every write (default is false)-->
<trace autoflush="true"/>
</system.diagnostics>
messageLogging
<system.serviceModel>
<diagnostics>
<messageLogging
logEntireMessage="true"
logMalformedMessages="false"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="false"
maxMessagesToLog="3000">
<filters>
<!--add xpath filter if rqd-->
</filters>
</messageLogging>
</diagnostics>
Notes
- For end to end activity tracing use source name="System.ServiceModel" switchValue="ActivityTracing" propogateActivity="true"
propogateActivity crosses endpoints (it passes a message header "ActivityId" with a ProcessAction id) - Add custom tracing as normal: new TraceSource("Custom").TraceData(TraceEventType.Information, 0, "Here");
- Performance counters: <system.serviceModel> <diagnostics performanceCounters="ServiceOnly">
="All" is ServiceModelService, ServiceModelEndpoint and ServiceModelOperation. - To log personally identifiable info, in machine.config <system.serviceModel><machineSettings enableLoggingKnownPii="true" /> and then <source name="System.ServiceModel.MessageLogging" logKnownPii="true">