15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

19<br />

instrumentation<br />

WhaT ’ s in This ChaPTer<br />

➤<br />

➤<br />

➤<br />

➤<br />

Code contracts<br />

Tr a c i n g<br />

Event logging<br />

Performance monitoring<br />

This chapter helps you to get live information about your running application to fi nd the issues that<br />

your application might have during production or to monitor resources needed to adapt earlier to<br />

higher user loads. This is where the namespace System.Diagnostics comes into play.<br />

One way to mark errors in your application, of course, is by throwing exceptions. However, an<br />

application might not fail that badly, but still not behave as expected. The application might be<br />

running well on most systems, but might have a problem on a few. On the live system, you can change<br />

the log behavior by changing a confi guration value <strong>and</strong> get detailed live information about what ’ s<br />

going on in the application. This can be done with tracing.<br />

If there are problems with applications, the system administrator needs to be informed. With the<br />

Event Viewer, the system administrator can both interactively monitor problems with applications <strong>and</strong><br />

be informed about specifi c events that happen by adding subscriptions. The event - logging mechanism<br />

allows you to write information about the application.<br />

To analyze resources needed from applications, monitor applications with specifi ed time intervals,<br />

<strong>and</strong> plan for a different application distribution or the extension of system resources, the system<br />

administrator can use the Performance Monitor. You can write live data from your application by<br />

using performance counts.<br />

New in .<strong>NET</strong> 4 are classes that offer design - by - contract in the namespace System.Diagnostics<br />

.Contracts . With these classes, you can defi ne preconditions, postconditions, <strong>and</strong> invariants that can<br />

be checked during runtime but also with a static contract analyzer.<br />

This chapter explains these facilities <strong>and</strong> demonstrates how you can use them from your applications.<br />

Code ConTraCTs<br />

Design - by - contracts is an idea from the Eiffel programming language. Now .<strong>NET</strong> 4 includes classes<br />

for static <strong>and</strong> runtime checks of code within the namespace System.Diagnostics.Contracts that<br />

can be used by all .<strong>NET</strong> languages.<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!