How to include DebugInformationProvider in Exception Handling Application Block

Topics: Building and extending application blocks, Exception Handling Application Block, Logging Application Block
Feb 7, 2011 at 7:07 PM

Hi guru,

My application uses Exception Handling Application Block to handle exception handling.  Now, I need to include additional functionality found in the Enterprise Library.

Enterprise Library has LogEntry class to log additional context information such as ComPlusInformationProvider, DebugInformationProvider, ManagedSecurityContextInformationProvider, and UnmanagedSecurityContextInformationProvider. 

But it's unclear how to attach these extra information into Exception Handling Application Block.  The document only demonstrates these function as code, but I cannot tell how to incorporate these code decoratively as part of Exception Handling Application Block.

Can someone share his thought on how to make this possible?

Thanks in advance.

Feb 8, 2011 at 2:38 AM

Hi,

As stated in the documentation - "The ExtraInformation providers add the information to a dictionary. You can choose which providers to use (if any) and add the resulting dictionary to the LogEntry.ExtendedProperties property.". Given this, the approach I can think of is to iterate thru the values of the extra information dictionary object and add it in the exception Data collection property that will then be handled by your EHAB.

It may look something like this;

            ExceptionManager exManager = EnterpriseLibraryContainer.Current.GetInstance<ExceptionManager>();
            try {
                throw new Exception("test exception with extra info");
            }
            catch (Exception ex)
            {
                DebugInformationProvider debugProvider = new DebugInformationProvider();
                IDictionary<string, object> dict = new Dictionary<string, object>();
                debugProvider.PopulateDictionary(dict);

                foreach (var item in dict)
                {
                    ex.Data.Add(item.Key, item.Value);
                }

                exManager.HandleException(ex, "Policy");

            }

Hope this helps.

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