Brian,

The first thing to decide is what you are trying to achieve with your
logging. Logging can be used for may purposes: error reporting, user status
messages, auditing etc... The best practices depend on your purpose and your
target audience. You may target your logging at: developers, system support
staff, system administrators, end users or all of them. The way in which you
present the log and the information it contains depends on these decisions.

Logging function arguments and return values is typically only usefull for
the software developers working on the project. As a general rule I don't
log the function arguments and return values. This is because logging at
this level tends to generate an unmanageable amount of information. During
development it is better to use a debugger to step through and analyze your
code, in the field it may be more appropriate to use a profiler to capture
the call flow and function arguments.

Typically I setup my logging to identify the root cause of a runtime error,
therefore it is crucial to log error conditions that occur. Whenever
possible check error conditions or catch exceptions and log a Warn or Error
level message if the condition is not expected. It is also important to
capture configuration information that led up to the error, typically logged
at a lower level. The best advice is to include as much contextual
information when an error occurs. You can use the nested diagnostic context
(NDC) and the mapped diagnostic context (MDC) to help capture this
information.

Ultimately you need to decide on the right level of logging for your
requirements, there must be enough logging to capture the error conditions
etc... but not too much that the cost of implementing the logging becomes
too high. 

Nicko

> -----Original Message-----
> From: Brian Beaudet [mailto:[EMAIL PROTECTED] 
> Sent: 17 February 2004 22:09
> To: [email protected]
> Subject: Logging Best Practices
> 
>  
> 
> I'd like to get some feedback on best practices with log4net 
> and logging  in general.  I've read through the documentation 
> and a few articles  about log4net however, I'd like to see 
> how others are using it.
>  
>   
>  
>  Currently I'm just sticking debug messages inside my 
> routines to see  when I entered/exited.  What else do you do?
>  
>   
>  
>  Thanks.
> 
>  
> 
>  
> 
>  
> 
>  
> 
> 

Reply via email to