If you want to “catch” and log the application messages at the “outermost” edge of your WCF service, then you should consider implementing an IDispatchMessageInspector
which will enable custom inspection of inbound/outbound service messages.
The following MSDN link provides an overview of the IDispatchMessageInspector
, which references your scenario:
Implement IDispatchMessageInspector to inspect or modify inbound or
outbound application messages either prior to dispatching a request
message to an operation or before returning a reply message to a
caller. There are a large number of scenarios that require
intercepting messages prior to invoking the operation for which it is
destined. For example, you can log incoming application messages or
perform some feature based on a message header.
http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.idispatchmessageinspector(v=vs.110).aspx
Alternatively, you could consider leveraging WCF Trace Logging with a custom database trace listener. In that way, to WCF will feed the trace data to the custom listener, which can insert into the database.
http://msdn.microsoft.com/en-us/library/ms733025(v=vs.110).aspx