WCF-Extensions can log the data from a request or response to anything you like. This can be helpful in a production environment where you can't sniff the trafic because of SSL certificates and breaking the production environment isn't an option either.
This projects supports writing to a TraceListener so it supports DebugView, EventLog, Files or even WebPage listeners. It is also possible to build your own and log to a database or an Azure Storage table.
To start copy the WCFExtensions.dll
to your WCF service bin
folder or next to the executable of your client.
Add the below section in your app.config
or web.config
file in the system.serviceModel
section.
<extensions>
<behaviorExtensions>
<add name="logBehavior" type="WCFExtensions.TraceEndpointBehaviorExtension, WCFExtensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
<behaviors>
<endpointBehaviors>
<behavior>
<logBehavior />
</behavior>
</endpointBehaviors>
</behaviors>
You can see a full sample app.config
configuration here.
TODO: provide a minimal web.config sample.
With this default configuration it will log to the DefaultTraceListener. You can check the output by using DebugView. More information is available here.
For more configuration options read the TraceListeners section below.
TraceListeners provide a way to log to a different output without changing the code. The default TraceListener writes to OutputDebugString which you can capture with DebugView.
The configuration below writes to a file called output.log
. Notice the tracelistener parameter for the logbehavior.
<system.diagnostics>
<trace autoflush="false">
<listeners>
<add name="log" type="System.Diagnostics.TextWriterTraceListener" initializeData="output.log" />
</listeners>
</trace>
</system.diagnostics>
<behaviors>
<endpointBehaviors>
<behavior>
<logBehavior tracelistener="log"/>
</behavior>
</endpointBehaviors>
</behaviors>
There are different types of TraceListener and if you want you can create your own. More documentation is available here.
Requirements
- Visual Studio 2013 (or newer)
Just open the WCFExtensions.sln
found in the src folder and built it like a normal project. You can also build from the commandline by calling msbuild WCFExtensions.sln
.