WebHttpBinding: Log all errors to service logfile
Posted
by W van Noort
on Stack Overflow
See other posts from Stack Overflow
or by W van Noort
Published on 2010-03-08T15:20:16Z
Indexed on
2010/03/08
15:21 UTC
Read the original article
Hit count: 542
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?
© Stack Overflow or respective owner