Ray,
As Chad stated, you can use Reflection to do what you want.
IMHO doing the exception correctly is the "standardized" part! The person
designing the exception would/should design the exception per standards!
Also won't you be logging duplicate information in most cases? (As most
exception classes are standardized, then you have your code to catch this
info for non-standardized exceptions...)
Or missing information in cases where there was an InnerException?
The following are a couple of articles on Exception Standards:
http://msdn.microsoft.com/library/de...Guidelines.asp http://msdn.microsoft.com/library/de...rp08162001.asp
Hope this helps
Jay
"Ray Cassick (Home)" <rc************@enterprocity.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Yeah, I know about that property. I was just trying to get something
wrapped up that would be a bit more standardized and not depend on the person that
designed the exception class.
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:#Y**************@TK2MSFTNGP11.phx.gbl... Ray,
I would expect custom Exceptions to override the Exception.ToString
method to include this information in a readable & sensible format for you.
All the exception that I have used from the Framework do this for you, I
would expect any one implementing their own exceptions to also do the
same! Either by overriding Exception.ToString itself or overriding
Exception.Message (which ever made the most sense for the use of the
custom Exception).
Hope this helps
Jay
"Ray Cassick (Home)" <rc************@enterprocity.com> wrote in message
news:Oo*************@TK2MSFTNGP12.phx.gbl... I am trying to create a generic logging component that will accept an
exception object and create a string containing all the properties and
their values available for a specific exception.
My intent here is try to create a generic function that will be able
to:
- Take a an object of type Exception...
- Iterate through all the properties the object has...
- Add the property names to a stringbuilder...
- Call each of the properties and get the values...
- Add each of the values to the string builder.
I can get all the basic properties that System.Exception provides
(Message, Source, Inner Exception, Target Site, Stack Trace, etc...) but I would
also like to be bale to get any customer properties provided by the more
specific exceptions and also print them out.
Can anyone point me to a piece of code that will help? I would also
like to be able to print the specifics on custom exceptions that are not part
of the framework but I am thinking that I am not going to be able to get much
deeper than the standard properties provided by the base exception the
custom exception inherits from.
Any ideas out there?