CSLA n-tier with Enterprise Library Logging to DB

CSLA n-tier with Enterprise Library Logging to DB

Old forum URL: forums.lhotka.net/forums/t/9027.aspx


k2so posted on Thursday, June 03, 2010

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

Once we enable the CSLA 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 CSLA object, and do a call to the same CSLA WCF data portal whenever we need to save to a database. Any comments on this approach?

Curelom replied on Thursday, June 03, 2010

What I have done is create a specific database for logging.  I then setup a connectionstring on the client side & server side that only has rights to execute the log entry stored procedure.  If the user was able to figure out the password, all they would be able to do is add more logs.  I don't know if this is the best approach, but it works.

k2so replied on Friday, June 04, 2010

Thx, that's a simple working solution. Smile

Some of these logs will be for audit purposes, hence although unlikely, users being able to insert more logs is not a preferred outcome.

I have read that we can create a custom TraceListener that logs to service instead of the DB, has anyone had experience implementing this or can give me some references to look to?

k2so replied on Thursday, July 15, 2010

Just want to post the solution I implemented if for others to find useful.

I ended up implementing the custom TraceListener (WcfDbTraceListener), which is contains a CSLA business object (WcfLogEntry). All WcfDbTraceListener is doing is to instantiate the WcfLogEntry, then call a save whenever the Write is called. By doing it this way, all logs would be logged to whichever app server and database we decide to switch to and all existing logging code can remain, all that we need to do is to switch (specified in the app.config) from DBTraceListener to WcfDbTraceListener on the client side.

The WcfLogEntry is a wrapper to the original LogEntry, with all properties defined in the CSLA way.

Creating a Custom Trace Listener: http://msdn.microsoft.com/en-us/library/ff648533.aspx

 

 

Copyright (c) Marimer LLC