Question

I have a set of wcf services that interact with a sql server database and I want to add some auditing to it to find when the service was called and what it did.

I believe there are 2 options open to me.

a. add triggers to the database tables that log to another database on updates, inserts etc b. add an interceptor to my wcf services which log calls to Mongo big data storage database with necessary data to audit

What is the best practise in this area and any suggestions as to an approach to follow?

Was it helpful?

Solution 2

As a first-response, I would try enabling tracing. You'd be surprised what kind of detail these can provide, especially in a diagnostic manner. It's also very simple and doesn't involve any recompilation:

<system.diagnostics>
    <trace autoflush="true" />
    <sources>
            <source name="System.ServiceModel" 
                    switchValue="Information, ActivityTracing"
                    propagateActivity="true">
            <listeners>
               <add name="sdt" 
                   type="System.Diagnostics.XmlWriterTraceListener" 
                   initializeData= "SdrConfigExample.e2e" />
            </listeners>
         </source>
    </sources>
</system.diagnostics>

And if you use Verbose logging, you'll get debug-level logging of almost every event going on. Then use SvctraceViewer to go back and audit these logs.

Beyond that, look in to using the Trace.* methods within your service to provide any additional level of detail you may need (like calls to and from the database). Depending on how you set the up service, you can probably also look in to a debugger that plugs right in to your database context and outputs when it makes calls to and from.

OTHER TIPS

An old question, but I've been working on a library that could probably help others.

With Audit.Wcf (an extension for Audit.NET), you can log the interaction with your WCF service, and you can configure it to store the audit logs in a MongoDB database by using the Audit.MongoDB extension.

[AuditBehavior] // <-- enable the audit
public class YourService : IServiceContract
{
  public Order GetOrder(int orderId)
  {
    ...
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top