Trace all the calls (+ their stack) made to a WCF

2019-05-07 11:33发布

I have a WCF Service which is currently in Production. The code performance are not where we would like them to be and we are unable to reproduce in our Staging environment.

I was wondering if it is possible to log every single method call made to the service and by the service. Essentially I would like a sequential list of all the calls and time stamps (our code isn't multi-threaded).

Is there a way to achieve that without having to instrument the binaries. Is there a level of tracing under the system.diagnostic node in the web.config that we could change?

2条回答
疯言疯语
2楼-- · 2019-05-07 11:33

Have you configured tracing in your configuration file? This is a good article on the subject.

Here is a sample configuration you can use and modify for your needs:

<system.diagnostics>
    <trace autoflush="true" />
    <sources>
        <source name="System.ServiceModel"
                switchValue="Information, ActivityTracing"
                propagateActivity="true">
            <listeners>
                <add name="ServiceModel"
                     type="System.Diagnostics.XmlWriterTraceListener"
                     initializeData="C:\ServiceModel.svclog" />
            </listeners>
        </source>
        <source name="System.ServiceModel.MessageLogging">
            <listeners>
                <add name="MessageLogging"
                     type="System.Diagnostics.XmlWriterTraceListener"
                     initializeData="C:\MessageLogging.svclog" />
            </listeners>
        </source>
    </sources>
</system.diagnostics>

<system.serviceModel>
    <diagnostics>
        <messageLogging logEntireMessage="True"
                        logMalformedMessages="False"
                        logMessagesAtServiceLevel="True"
                        logMessagesAtTransportLevel="False"
                        maxMessagesToLog="10000"
                        maxSizeOfMessageToLog="10000" />
    </diagnostics>
</system.serviceModel>

Use the Service Trace Viewer Tool (SvcTraceViewer.exe) to view the resulting logs.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-05-07 11:59

Check WCF Tracing and optionally also WCF message logging and use SvcTraceViewer to check collected data - you can alternatively build your trace listener for logging traces for example to database. WCF also provides performance counters.

查看更多
登录 后发表回答