title: Masking sensitive information when logging from IClientMessageInspector
body: <p>I'm using WCF (.NET 3.5) to communicate with a server using SOAP.  When running in debug mode, I use <code>System.ServiceMode.Dispatcher.IClientMessageInspector</code> and log4Net to log the request content.  </p>
  
  <pre><code>public object BeforeSendRequest(ref Message request, IClientChannel channel)
  {
      log.Debug(request); 
  }
  </code></pre>
  
  <p>My difficulty is that sometimes the SOAP message contains authentication information that I must mask before writing to the logs 
  e.g. in the following example I would like to log the password element as <code>&lt;password&gt;**********&lt;/password&gt;</code></p>
  
  <pre><code>&lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
      &lt;s:Header&gt;
          &lt;Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none"&gt;http://service.soap.host.com/credentials&lt;/Action&gt;
      &lt;/s:Header&gt;
      &lt;s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
          &lt;credentials xmlns="http://service..soap.host.com/credentials"&gt;
              &lt;username&gt;MyUsername&lt;/username&gt;
              &lt;password&gt;MyPassword&lt;/password&gt;
          &lt;/credentials&gt;
      &lt;/s:Body&gt;
  &lt;/s:Envelope&gt;
  </code></pre>
  
  <p>I'm able to achieve this in a crude way using regular expression matching on the output of <code>request.ToString()</code> but I wonder if there's a more elegant and efficient approach that will allow me to modify the value of the password element before converting the message to a string.</p>