Is it possible to log exception like ThrowMaxReceivedMessageSizeExceeded from my WCF service. I know that the message size can be increased in the config but I would also like it logging on my side. I have Log4Net running to catch all unhandled exceptions but it seems this is so not getting logged, so is probably handled.
Leverage fault exceptions in WCF to transmit user friendly error messages to the presentation layer when exceptions occur. Exceptions are errors that occur at runtime; exception handling is the technique of handling these runtime errors.
Expected exceptions from communication methods on a WCF client include TimeoutException , CommunicationException , and any derived class of CommunicationException . These indicate a problem during communication that can be safely handled by aborting the WCF client and reporting a communication failure.
WCF tracing is built on top of System. Diagnostics. To use tracing, you should define trace sources in the configuration file or in code. WCF defines a trace source for each WCF assembly.
You need to enable Tracing. That can be sent to Nlog. My XYZ.exe.config has a section which looks like that:
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Error" propagateActivity="true" >
<listeners>
<add name="nlog"/>
</listeners>
</source>
<!--source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="nlog" />
</listeners>
</source-->
</sources>
<sharedListeners>
<add name="nlog" type="NLog.NLogTraceListener, NLog" />
</sharedListeners>
</system.diagnostics>
NOTE: I have the NLog config in the XYZ.exe.config as well!
EDIT
I just realized that you were talking about log4net. Not NLog.
If you follow the last link provided by StephaneT and implement the Log4netTraceListener
you should be able to use the XYZ.exe.config solution as well.
By default, WCF uses system.diagnostics tracing to log exceptions. See here and here and here
You can redirect system traces to log4net as explained in this question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With