Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log WCF message content?

Tags:

.net

logging

wcf

enter image description here

I thought this would be simple, but I can't see how to tell WCF to log message bodies. I have:

<system.diagnostics>   <sources>     <source name="System.ServiceModel" switchValue="Verbose">       <listeners>         <add type="System.Diagnostics.DefaultTraceListener" name="Default">           <filter type="" />         </add>         <add type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EntLibLoggingProxyTraceListener,Microsoft.Practices.EnterpriseLibrary.Logging"           name="traceListener">           <filter type="" />         </add>       </listeners>     </source>   </sources> </system.diagnostics> <system.serviceModel>    <diagnostics>      <messageLogging logEntireMessage="true" logMalformedMessages="true"        logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="false" />    </diagnostics>    ...etc..,    ...etc... </system.Model> <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">    <listeners>      <add fileName="_trace-xml.log"                 listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.XmlTraceListenerData,Microsoft.Practices.EnterpriseLibrary.Logging"                 traceOutputOptions="None"                 type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.XmlTraceListener,Microsoft.Practices.EnterpriseLibrary.Logging"         name="XML Trace Listener" />            ...etc... other listeners   </listeners>   ...etc... </loggingConfiguration> 

But all I get logged is stuff about the message, not the message body. What do I need to change to log message content?

like image 285
Chris F Carroll Avatar asked Nov 08 '11 13:11

Chris F Carroll


People also ask

How do I enable tracing and message logging in WCF?

To activate message logging, you must add a trace listener to the System. ServiceModel. MessageLogging trace source and set attributes for the <messagelogging> element in the configuration file. The following example shows how to enable logging and specify additional options.

How do I check WCF logs?

Viewing Event Logs. Event logging is enabled automatically by default, and there is no mechanism to disable it. Events logged by WCF can be viewed using the Event Viewer. To launch this tool, click Start, click Control Panel, double-click Administrative Tools, and then double-click Event Viewer.

What do message loggers do?

The message logging facility, when active, writes messages to the log data set containing all data that simulated resources transmit or receive in a specified network. Most users use the message logging facility because of its usefulness for analyzing network simulations.

How do I enable WCF tracing on client?

ServiceModel. MessageLogging trace source records all messages that flow through the system. Tracing is not enabled by default. To activate tracing, you must create a trace listener and set a trace level other than "Off" for the selected trace source in configuration; otherwise, WCF does not generate any traces.


2 Answers

Just following this description works perfectly for me: http://msdn.microsoft.com/en-us/library/ms730064.aspx

<system.diagnostics> <sources>   <source name="System.ServiceModel.MessageLogging">     <listeners>              <add name="messages"              type="System.Diagnostics.XmlWriterTraceListener"              initializeData="c:\logs\messages.svclog" />       </listeners>   </source> </sources> </system.diagnostics>  <system.serviceModel> <diagnostics> <messageLogging       logEntireMessage="true"       logMalformedMessages="false"      logMessagesAtServiceLevel="true"       logMessagesAtTransportLevel="false"      maxMessagesToLog="3000"      maxSizeOfMessageToLog="2000"/> </diagnostics> </system.serviceModel> 

No need to write any code for that ...

like image 90
kroonwijk Avatar answered Oct 09 '22 07:10

kroonwijk


I found an versioning issue. When the WCF Service project was built against .Net 3.5 I saw the full message body in the viewer tool. Built against .Net 4.0 I saw no message body.

like image 45
RichardHowells Avatar answered Oct 09 '22 08:10

RichardHowells