WebHttpBinding: Log all errors to service logfile
- by W van Noort
I have a self-hosted WCF service that uses a WebHttpBinding. In the implementation of the service, all exceptions are caught and a appropriate message is returned to the caller. All exceptions are also logged to the service logfile.
catch (Exception ex)
{
_log.Error("Error posting message", ex);
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.InternalServerError;
return string.Format("{0}:error={1}", (int)HttpStatusCode.InternalServerError, ex.Message);
}
However, some situations are intercepted by the WCF framework. e.g.: when the client sends a message that exceeds the configured quotum, i never get an entry in my log file.
In fact, i only found this, by adding this to the config file, and inspecting the generated trace file.
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
<listeners>
<add name="xml" />
</listeners>
</source>
<source name="CardSpace">
<listeners>
<add name="xml" />
</listeners>
</source>
<source name="System.IO.Log">
<listeners>
<add name="xml" />
</listeners>
</source>
<source name="System.Runtime.Serialization">
<listeners>
<add name="xml" />
</listeners>
</source>
<source name="System.IdentityModel">
<listeners>
<add name="xml" />
</listeners>
</source>
</sources>
<sharedListeners>
<add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\test\Traces.svclog" />
</sharedListeners>
Is there a way to get these kind of errors visible in my own logfile?