Eds
Eds

Reputation: 157

WCF Exception Logging

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.

Upvotes: 5

Views: 6260

Answers (2)

toATwork
toATwork

Reputation: 1377

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.

Upvotes: 5

stombeur
stombeur

Reputation: 2714

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.

Upvotes: 3

Related Questions