Hi all,
 
I don't think I have grasped something basic about using error handling as I am having trouble integrating exceptions with logging. The goal of my logging is at high levels to be comprehensible to a non software engineer and provide sufficient information to fix any problem that has occurred. Exceptions are the default error handling of .Net and almost every object can throw them in some situation. Catch handlers around every call is not realistic but the level of detail I add to the NDC is sufficient.
 
The problem is that if I log an exception message at the catch handler, I have lost the context of the NDC and the resultant log message is unhelpful. What are the other options? What design guidelines do you set down?
 
i) Log the exception's call stack
 
    This does not give presentable messages
 
ii) Log and throw at the same time
 
    This can cause the same message to be logged repeatedly through the hierarchy as the error ripples up to the top level. Ugly and harms admin's ability to use log4net to trigger actions based on trace message contents.
 
c) Append the NDC to an exception message
 
    Suffers from both the previous problems - its not nice that the NDC becomes part of them message and rethrowing an exception will cause multiple copies of the NDC.
 
 
Thanks in advance for your ideas,
 
Duncan
 
   

Reply via email to