tags:

views:

48

answers:

3

The WCF channel is somehow getting into the faulted state in the client, what WCF logging show I enable to help track down the reason?

How do I enable the given logging from code? (The channel etc is setup in code rather than a config file on each side)


Edit: Both sides are Winforms applications, so I don’t have a web.config file, but I do have a app.config file.

+2  A: 

You don't need to add the logging in code. On both the service (web.config) and the client (app.config) add this:

<system.diagnostics>
<sources>
  <source name="System.ServiceModel" switchValue="Verbose, ActivityTracing">
    <listeners>
      <add name="xml"/>
    </listeners>
  </source>
  <source name="System.ServiceModel.MessageLogging" switchValue="Verbose">
    <listeners>
      <add name="xml"/>
    </listeners>
  </source>
</sources>
<sharedListeners>
  <add name="xml" type="System.Diagnostics.XmlWriterTraceListener" 
     initializeData="c:\logs\logfilename.svclog"/>
</sharedListeners>
<trace autoflush="true"/>
</system.diagnostics>

You should use the Service Trace Viewer (SvcTraceViewer.exe, included in SDK v6.0a) to view the files.

klausbyskov
thanks, unlike log4net, system.diagnostics seems not to create the folders, therefore the above did not work for me until I create a c:\logs folder.
Ian Ringrose
that is right. Sorry that I forgot to mention that.
klausbyskov
+1  A: 

you can still enable logging from web.config using system.diagnostics element (even if your channel was setup in code).

here are some msdn links: (1) (2)

You can also have a look > here < for step by step walkthrough.

jarek
sorry I did not say, both sides are Winforms applications, so I don’t have a web.config file, but I do have a app.config file.
Ian Ringrose
you can do the same in app.config
jarek
A: 

A bit of a shot in the dark, but this may be more of a debugging issue than a logging one.

You may need to check that your connections are being closed or pooled correctly. I use netstat from the command line to keep track of the open connections to the service to verify that connections are closed when I think they should be.

grenade