开发者

Why can't I trace just errors on the service side of my WCF?

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜