Logging to DB through WCF data portal

Topics: Logging Application Block
Jun 3, 2010 at 3:22 PM

We have Enterprise Library logging set up to log our business objects. We want to capture some of the errors to the database. This works fine when we are running everything local.

Once we enable a WCF data portal to switch to a 3-tiers model, the logging to database no longer works on the client side, because in the Enterprise Library config, it simply specifies a stored procedure name that saves the log entry, but now the client has no more direct access to the database.

I am wondering if anyone encountered the same problem and had a workaround for it.

 

All I can think of now, is to wrap the Enterprise Library LogEntry and Logger as serializable object, and do a call to the same WCF data portal whenever we need to save to a database. Any comments on this approach?

Jun 3, 2010 at 5:38 PM

I'm a bit unclear on where does the exception logging to the database is configured, is it the client side or the WCF/server side? I think one thing that you may also want to consider is from where the exception came from, either from the client side or in the WCF itself.

Also, I'm thinking of instead of passing the LogEntry object to the WCF how about using the Exception object (since as mentioned, error/exception are the one being captured to be logged in the database) as an argument parameter of an operation contract of your WCF that will then execute the exception logging into the database. By doing this you can also try and see the options of creating an Exception Policy from your client side app with a Custom Exception Handler that will deal with the WCF operation contract calling, passing from there your Exception Object.   

Gino Terrado
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jun 3, 2010 at 6:21 PM

Sorry being not too clear.

The database is configured on the server side. The client has no direct access to database at all, it needs to go through the WCF data portal service to do any DB get, insert, update, delete.

The default Logger is being used at the moment to call the logging on both the client and server sides.

 

I am guessing there isn't a ready-to-use method to call the logging to log through the WCF service, thanks for the suggestion however, I will try it out and see if everything works fine.

 

 

Jun 3, 2010 at 6:25 PM

You'll need to write a custom trace listener that knows how to talk to your service. The DatabaseTraceListener only does that - write to a database directly.

 

Jun 4, 2010 at 2:30 PM

Thanks! I think this might be the better solution.

Are there any documentation or samples on how to do this? Are we able to configure the custom trace listener in the config, just like the other out of the box trace listeners?

Jun 7, 2010 at 2:45 AM

Creating a custom trace listener is included in the documentation.  On your question if you can configure it in the config, yes, you certainly can.  You have 2 options, the basic integration or full integration.  Detailed steps on how to implement each of these two is also included in the documentation. (Click on the basic integration or full integration link.)

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@Avanade.com

Jun 7, 2010 at 6:51 PM
AvanadeSupport wrote:

Creating a custom trace listener is included in the documentation.  On your question if you can configure it in the config, yes, you certainly can.  You have 2 options, the basic integration or full integration.  Detailed steps on how to implement each of these two is also included in the documentation. (Click on the basic integration or full integration link.)

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@Avanade.com

Thanks.