The Enterprise Library Logging Application Block allow you to create log messages and send those messages to different targets of output. The most typical output targets include a console window, file, database, web services and email though any conceivable target could be configured.
Logging Configuration has three major components
- Trace Source
Trace sources act as the link between the log entries and the log targets.
- Trace Listener
Trace listeners are responsible for taking the log entry, passing it through a separate log formatter and passing it to the target log.
- Log Formatter
Log Formatter translates the content into a suitable format.
Have you ever wonder, what really happens in a try – return – finally statement? The finally statement is executed, but the return value isn’t affected. The execution order is:
- Code before return statement is executed
- Expression in return statement is evaluated
- finally block is executed
- Result evaluated in step#2 is returned
In general, in today’s implementations, entering a try block is not expensive at all (this was not always true). However, throwing and handling an exception is usually an expensive operation. So, exceptions should only be used for exceptional events.
Refer this article for further details. In general, check will be cheap; processing the exception may not be.
An exception is an error that occurs at runtime and terminates the normal flow of execution of a program if not handled properly. Exception handling is the technique of handling runtime errors in your application code. When exceptions occur, you may not want to reveal the actual stack trace or exception message to the user.
Custom exceptions can be used to customize the exception information or add meaningful information to your exceptions when they occur while the program is in execution.