Custom properties in a Custom Handler

Topics: Exception Handling Application Block
Nov 5, 2009 at 4:00 PM
Edited Nov 5, 2009 at 4:03 PM

Greetings,

I have an Exception Policy to handle the exceptions from the type System.Exception. I have a Custom Handler, and I want to pass an attribute to my Custom Handler.

I added it in General, Attributes, Collection and set a Key and a Value for my attribute.

Does anybody know how I can retrieve my attribute information in my Custom Handler?

Thanks,

 

Paco Cruzado

Nov 6, 2009 at 1:06 AM

You can access it in your custom handler thru the Attributes property.  The contents will be available except in the constructor. 

string myValue = this.Attributes["myKey"];

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Nov 6, 2009 at 6:40 AM

That's what I tried the first time, but I wasn't able to reach the attributes, maybe I have a wrong structure.

I'm working in VB and my Custom Handler implements the Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.IExceptionHandler interface.

I can't access to the attributes from the object Me, and I don't know if I'm missing something.

I've traid with this:

     Public Class ManejadorExcepcionesPresentacion
        Implements Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.IExceptionHandler

        Public Function HandleException(ByVal exception As System.Exception, ByVal handlingInstanceId As System.Guid) As System.Exception _
            Implements Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.IExceptionHandler.HandleException
            Try
                Dim messageAs String = Me.attributes("GlobalMessage")
            Catch ex As ThreadAbortException
            End Try

            Return exception

        End Function

        Public Sub New(ByVal ignore As NameValueCollection)
        End Sub

        Public Sub New()
        End Sub
    End Class

Thanks



 

Nov 6, 2009 at 6:49 AM

When you said you can't access the attributes, are you saying there's no Attributes property available in the Me object or the contents you entered in the config are not present in the Attributes property?

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Nov 6, 2009 at 6:52 AM

The first one, there is no Attributes property in the Me object.

 

Nov 6, 2009 at 7:03 AM

My bad, I was so used to a custom trace listener.  To get the values of the Attributes property collection, create a constructor that takes a NameValueCollection parameter.   That parameter will contain the items you added in the Attributes property.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com