Not able to get the attribute property in custom handler

Topics: Exception Handling Application Block
Apr 28, 2010 at 7:50 AM
hi, I have created both custom tracelistner and custom handler. In custom tracelistner and able to get the attribute property . but i'm not able to get the attribute property in custom handler. here is the code. Custom tracelistner. [ConfigurationElementType(typeof(CustomTraceListenerData))] public class CustomMsmqTraceListner : CustomTraceListener { public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data) { using (var queue = new MessageQueue(Attributes["QueuePath"])) { try { } } } here am able to get this Attributes. but here is my custom handler code [ConfigurationElementType(typeof(CustomHandlerData))] public class CustomMsmqHandler : IExceptionHandler { public Exception HandleException(Exception exception, Guid handlingInstanceId) { //here am not able to get this Attribute property } Do i have inherit from some other class? }
Apr 28, 2010 at 9:34 AM

Hi sumeethp, I recall answering a question from you about the Attributes property.  I forgot that a custom exception handler doesn't have this.  But you can still get the value of the Attributes property you specified in the config by providing a constructor which takes a NameValueCollection parameter.  Assign it then to a class level variable.

[ConfigurationElementType(typeof(CustomHandlerData))] 
public class CustomMsmqHandler : IExceptionHandler
{
    private NameValueCollection attributes;
    public CustomMsmqHandler(NameValueCollection attributes)
    {
            this.attributes = attributes;
    }
}

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

Apr 29, 2010 at 5:19 AM
Sarah, Thanks again. I will try this and let you know.
Apr 29, 2010 at 5:40 AM
its working great! thank you