20.2. Events and Event Logs

Events are probably the most important part of monitoring the application. They provide valuable information to the operations and support teams regarding the application's internal state, especially under abnormal conditions. Although performance counters offer processing performance and other internal state-related information, events can contain far more information than simple values that can be sampled.

Windows-based applications can raise events using the EventLog class. An event can be of type Information, Warning, Error, Success Audit, or Failure Audit. The events raised by the application are stored in a specific "event log." An event log is a special type of log file and is not to be confused with debug or trace logs. Applications use the Debug and Trace classes to output information that helps to trace program execution and assist in debugging activities. The events raised by the application should indicate information that is useful from an operational point of view, not "spam" the event log with unnecessary information. The following simplified pseudo code shows a hypothetical example of a program flow using both event logging and tracing:

Trace.WriteLine "Process Started" // trace execution Trace.WriteLine "Checking AccountState 'AccountState' for Account 'thisAccount'" if( thisAccount.AccountState == AccountStates.New ) { try { // process account . . . Trace.WriteLine "Account 'AccountId' Processed Successfully" } catch( Exception e ) ...

Get Design – Build – Run: Applied Practices and Principles for Production-Ready Software Development 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.