Logging handler in Exception handling application block

Topics: Building and extending application blocks, Exception Handling Application Block, Logging Application Block
Mar 1, 2010 at 7:37 PM

Is it possible to send a custom LogEntry object to the logging app block from the exception handling block?

Mar 2, 2010 at 12:41 AM
Edited Mar 2, 2010 at 12:44 AM

Hi,

Yes it would be possible but you would have to write your own custom Logging handler. Why would you send a custom log entry? is there just some stuff that you want to add to the logs? There is another approach, a quick one, if you would only want to add, lets say the current user, you could add something to the Data property of the Exception then it will be automatically appended to the Extended Properties of the Log.

	   try
            {
                throw new Exception("Error Occurred.");
            }
            catch (Exception ex)
            {
                //add something
                ex.Data.Add("OS Service Pack : ", Environment.OSVersion.ServicePack);

                if (ExceptionPolicy.HandleException(ex, "EP"))
                {
                    throw;
                }
            }

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

Mar 2, 2010 at 1:44 PM

Valiant,

    Thanks for a quick reply. I did evaluate that approach. But, the problem we are facing with is, there is some critical information in the exception message that we dont want to log. For which i have designed a custom handler which essentially is a logger but truncates the critical information before it sends it to the logginig application block. I was wondering if that can be acheived without a custom handler. So, I thought if there was any way I can instruct the enterprise library to feed a particular log entry object i wouldnt need a custom handler.

Thanks

Karteek

Mar 3, 2010 at 1:10 AM

No, you do need to create a custom handler for this.

 

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

Mar 3, 2010 at 3:26 PM

Thanks Sarah