O'Reilly logo

Professional Visual Basic 2012 and .NET 4.5 Programming by Todd Herman, Gastón Hillar, David McCarter, Rob Windsor, Billy Hollis, Bill Sheldon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Logging Errors

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:

1. Write error information in a text file or flat file located in a strategic location.
2. Write error information to a central database.
3. Write error information to the system's Event Logs, which are available on all versions of Windows supported by the .NET Framework 4 or later. The .NET Framework includes a component that can be used to write to and read from the System, Application, and Security Logs on any given machine.

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required