Capturing error information is important for troubleshooting. Not only is it common for a user to forget details related to what error they received and how they got there, but if you've handled the error and replaced the default error message, the real error probably isn't even visible. Logging errors enables you to get the specific error message without re-creating the error or needing to provide details that are visible to an end user.
While error logging is very important, you only want to use it to trap specific levels of errors, because it carries overhead and can reduce the performance of your application. Your goal should be to log errors that are critical to your application's integrity—for instance, an error that would cause the data that the application is working with to become invalid.
There are three main approaches to error logging:
The type of logging you choose depends on the categories of errors you wish to trap and the types of machines on which you will run your application. If you choose to write to an Event Log, ...