Error Handling

Topics: Logging Application Block
Nov 14, 2008 at 12:07 AM
Hi,

           I am using Logging block to log information into the database. I want to capture the data base error when something goes wrong.

Ex:  let assue stored procedure expecting 4 input parameters but we are passing 3 parameters. I want to capture this error and sotre into database. But when i tried the below code its is not going to catch block. It looks like logging block hiding the error.

Can you please advice me how i can capture the error?

Question 2:
Is there any way i can capture stack trace  and store into database?
Ex:  ex.StackTrace

Thanks in advance
RP


Nov 14, 2008 at 12:39 AM
Hi,

Can you post your sample code and your config?

For your question 2: You can assign your stack trace to the extendedProperties property (which is a dictionary type) of your LogEntry instance
see: http://msdn.microsoft.com/en-us/library/dd140115.aspx. Then with the use of your Custom Trace Listener, you can now insert the stacktrace to the database.

Ex.

catch (Exception ex) {

 

LogEntry entry = new LogEntry();

 

 

 entry.ExtendedProperties.Add(

new KeyValuePair<string,object>("StackTrace", ex.StackTrace);

 

 

  }

 

 

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com