Best practice for centralized exception logging (with Log4Net)?

Best practice for centralized exception logging (with Log4Net)?

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


rsbaker0 posted on Tuesday, February 03, 2009

I just started plugging in Log4Net into our application and am looking to log problems that occur accessing the DAL (e.g. anything from invalid SQL syntax to broken connections, query timeouts), etc.

Any thoughts on where the best place to inspect and log such exceptions would be? I'm fine with doing this on the server side of the data portal, so DataPortal_OnDataPortalException() looked promising.

RockfordLhotka replied on Tuesday, February 03, 2009

The data portal has pre-, post- and exception methods that it calls, in addition to the actual DataPortal_XYZ methods.

Those exist primarily to support scenarios like logging.

The 3.6 data portal also has an authorization concept that is called immediately as the request hits the server (right after the objects deserialize). This is intended for authorization of all requests, but could also be used for logging.

rsbaker0 replied on Tuesday, February 03, 2009

In this case I'm mainly looking for exceptions thrown by my DAL, so I think DataPortal_OnDataPortalException() will do the trick. It's nice to know that you could (at least in theory) log all of your data portal calls by hooking the pre/post methods.

Thanks!

 

RockfordLhotka replied on Tuesday, February 03, 2009

You might want to put the logging code in there anyway.

 

Keep in mind that log4net has various levels of logging – down to the info level. So you could do info logging in all the methods, and error logging in the ODPE() method. Normally the info logging would be turned off, but if you needed a detailed trace you could turn it on by changing the log4net config in the config file.

 

Just something to consider.

 

Rocky

Copyright (c) Marimer LLC