Chapter 19. Instrumentation

WHAT'S IN THIS CHAPTER?

  • Code contracts

  • Tracing

  • Event logging

  • Performance monitoring

This chapter helps you to get live information about your running application to find the issues that your application might have during production or to monitor resources needed to adapt earlier to higher user loads. This is where the namespace System.Diagnostics comes into play.

One way to mark errors in your application, of course, is by throwing exceptions. However, an application might not fail that badly, but still not behave as expected. The application might be running well on most systems, but might have a problem on a few. On the live system, you can change the log behavior by changing a configuration value and get detailed live information about what's going on in the application. This can be done with tracing.

If there are problems with applications, the system administrator needs to be informed. With the Event Viewer, the system administrator can both interactively monitor problems with applications and be informed about specific events that happen by adding subscriptions. The event-logging mechanism allows you to write information about the application.

To analyze resources needed from applications, monitor applications with specified time intervals, and plan for a different application distribution or the extension of system resources, the system administrator can use the Performance Monitor. You can write live data from your application by using performance counts ...

Get Professional C# 4 and .NET 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.