tags:

views:

17

answers:

1

I have a wcf service that sometimes creates errors like "The InnerException message was 'Maximum number of items that can be serialized or deserialized in an object graph is '65536'". I know how to fix this particular problem, but now I want to create a trace that saves only Errors (and Critical errors) to the log.

The problem is that my log saves either everything (including successful calls) or nothing at all. So my question is, what is wrong with my web.config?

<system.diagnostics>
    <trace autoflush="true" />
    <sources>
        <source name="System.ServiceModel" propagateActivity="true" switchValue="Error">
            <listeners>
                <add name="xml">
                </add>
            </listeners>
        </source>
    </sources>
    <sharedListeners>
        <add initializeData="C:\mylog.svclog"
             type="System.Diagnostics.XmlWriterTraceListener"
             name="xml" />
    </sharedListeners>
</system.diagnostics>

I have tried with all different combinations of the switchValue, but none gives me the result I want (= catch errors, but not successful calls).

Does anyone have an idea?

A: 

If you need to have service-side only logging, you might want to check out the IErrorHandler interface which you can put onto your service class.

This interface will expose two methods

public bool HandleError(Exception error)

public void ProvideFault(Exception error, MessageVersion ver, ref Message msg)

which would allow you to tap into all exceptions happening on the service-side - log those into a log file of your own, and you should be fine.

marc_s
Ah, yes you might be right, maybe it's easier to just use normal error tracing, and merge those errors with errors from the web site (which I store in a database).
Pete
I tried this and it works fine. (and I also learned that globala.asax Application_Error can NOT be used for this purpose)
Pete