Just like there is a command to flush IIS7 logs:
netsh http flush logbuffer
I'm wondering is there a similar command to flush WCF trace log on demand.
Setting the autoflush="true" in your .config file ensures that the trace sources flush to disk after each trace.
The following is a sample configuration file with autoflush="true":
<configuration>
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Warning, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="xml" type="System.Diagnostics.XmlWriterTraceListener"
initializeData="e2eTraceTest.xml" />
</listeners>
</source>
</sources>
<trace autoflush="true" />
</system.diagnostics>
</configuration>
In addition, if by any chance you are willing to store your WCF trace in a database, you might want to check out this post:
Stack Overflow: How can I enable WCF logging so that it writes to a Database?'
This would allow you to view your WCF trace in real-time, without flushing it.
One way is to do an IIS reset, but this is only really an option when debugging on a developmnet box.
Related
We have a WCF-based backend API implementation. We are dealing with a production problem, and we need to investigate just a single service erroneous behavior.
We need to get WCF Trace logs, but since the system is heavily stressed, we expect that activation for the whole application cannot be done.
What we need is to enable WCF tracing for selectively chosen URL (a single service).
We tried with the location element - to get the configuration applied only for particular folder/file.svc, but this does not work. Still we had to enable WCF Tracing for the whole IIS Application to get the traces generated.
Any idea how to enable WCF Tracing for a single service ?
WCF tracing is built on top of System.Diagnostics. You should define trace sources in the configuration file or in code for using trace like this:
<configuration>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:\log\Traces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
</configuration>
Also you can refer to this docs for further info.
I am writing an application that connects to the WCF service.
When I receive CommunicationException on the client side I need to understand whether the problem is on the service side or due to the invalid client configuration.
You can add the following section to your WCF host config file:
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
<listeners>
<add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="logs\WCFLog.svclog"/>
</listeners>
</source>
</sources>
</system.diagnostics>
this will create an svclog file which can give you more information about the cause of the connection problem.
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?
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.
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.
I'm sending files from clients to a server using WCF with different bindings. I need to know the sizes of the packets that the client send. How should I configure diagnostics in the config?? Or how can I view this?? Thanks.
To enable diagnostics, edit .config file
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
<listeners>
<add name="sdt" type="System.Diagnostics.XmlWriterTraceListener" initializeData="App_Data\WCF.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
Then you can open .svclog file with Microsoft Service Trace Viewer
See also:
Configuring Tracing at MSDN
Administration and Diagnostics at MSDN
Configuring Message Logging at MSDN
I've written a WCF service with a duplex contract which asynchronously calls back the clients. I have some issues when multiple clients get connected and i dono how to debug the service. Any insights on this?
Thank you.
NLV
A bit more info on what your problem is would be helpful, but to get you started try enabling diagnostics. Add the following to your service config and set "initializeData" to set where the log file is written. Opening the file should launch Microsoft Service Trace Viewer. You can do the same on the client side. If you have both a service log and client log in Trace Viewer go to Menu -> Add and select the other file. You will then get the message interactions matched up in the graph tab.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
...
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="System.ServiceModel"
switchValue="Verbose">
<listeners>
<add name="sdt"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="D:\wcfLog.svcLog" />
</listeners>
</source>
</sources>
</system.diagnostics>
</configuration>
More info here: Tracing