Return new record Id after logging an exception (EL 4.1)

Topics: Exception Handling Application Block
Mar 17, 2014 at 5:37 PM
We are writing exception details in a custom table using a stored procedure. This works great, but now we have to return the new record ID and I can't figure out how to do this. Here is the current code we have:

This is how we log the data inside the catch:
ADPDS.CustomExceptionHandler.ExceptionHandler.HandleException(ex, ADPDS.CustomExceptionHandler.ExceptionHandler.PolicyName.DBLog, info);
We have a custom HandleException code which eventually calls ExceptionPolicy.HandleException.

But they all return bool values.

This is the configuration code:
      <add WriteLogStoredProcedureName="x_webint_ErrorLogInsert" Server="ExceptionConnectionString" SourceApplication="ADPTS.Service" CurrentApplication="ADPTS.Service" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" traceOutputOptions="None" filter="All" type="ADPDS.CustomExceptionHandler.DatabaseTraceListener, ADPDS.CustomExceptionHandler, Version=, Culture=neutral, PublicKeyToken=null" name="DatabaseTraceListener" initializeData="" formatter="Text Formatter" />
      <add source="ADPTS.Service" formatter="Text Formatter" log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" traceOutputOptions="DateTime" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="EventLog TraceListener" />
      <add fileName="ADPTS.Service.log" footer="End----------------------------------------" formatter="Text Formatter" header="Begin----------------------------------------" rollFileExistsBehavior="Overwrite" rollInterval="Week" rollSizeKB="5000" timeStampPattern="yyyy-MM-dd" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" traceOutputOptions="DateTime" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="FlatFile TraceListener" />
How can I return the record ID after we call our custom stored procedure?

Thank you
Mar 18, 2014 at 12:29 AM
Unfortunately, there is no explicit place in the interface to return a record ID. (Also, the exception handler can be configured to throw an exception in which case the record ID won't be returned.)

The following question is very similar except that it deals only with the Logging Application Block:

In your case you would also need to find a way to get the record ID from the exception handler. If you are sure that an exception is going to always be returned it would be possible to add the record ID to the returned exception's Data IDictionary similar to using the LogEntry's ExtendedProperties. It's a bit of hoop jumping, though so it might make more sense to set a ThreadStatic variable in the custom trace listener which can then be read after the exception handler returns.

Randy Levy
Enterprise Library support engineer
Support How-to