Registering for Events


Once you've configured the providers you plan on using, you need to decide which events you want to funnel to each provider. You do this using the <eventMappings> and <rules> elements under the <healthMonitoring> section in web.config.

Event mappings define groups of events based on a class and/or range of event codes. Remember how every Web event is represented by a class? Since those classes form a hierarchy, it makes it easy to select an entire group of events through a base class. For example, Listing 7-6 illustrates a very useful event mapping defined in the root web.config file.

Listing 7-6. A default event mapping

<!-- excerpt from root web.config file that ships with ASP.NET 2.0 --> <healthMonitoring>   <eventMappings>     <add name="All Events"          type="System.Web.Management.WebBaseEvent"          startEventCode="0"          endEventCode="2147483647" />   </eventMappings> </healthMonitoring> 

This event mapping matches any Web event that is of (or derives from) the type WebBaseEvent and has an event code between 0 and Int32.MaxValue. In other words, this matches all events, even custom events that you might create for your application. The root web.config file defines several generic event mappings like this that you can use. These don't have any limit on the event code and are matched purely based on type. Table 7-3 lists the names of these default mappings, including the Web event type they match. These predefined mappings may satisfy your needs, but you can add your own more specific groups by including an <eventMappings> section in your web.config file.

Table 7-3. Built-in event mappings

Event Mapping Name

Matching Web Event Type

All Events

WebBaseEvent

Heartbeats

WebHeartbeatEvent

Application Lifetime Events

WebApplicationLifetimeEvent

Request Processing Events

WebRequestEvent

All Errors

WebBaseErrorEvent

Infrastructure Errors

WebErrorEvent

Request Processing Errors

WebRequestErrorEvent

All Audits

WebAuditEvent

Failure Audits

WebFailureAuditEvent

Success Audits

WebSuccessAuditEvent


Once you have a set of event mappings that's granular enough for what you're doing, you can start funneling those events onto providers using rules. A rule is how you register a provider to listen for a group of events. The order of rules isn't important, and it's completely possible for any given event to be matched by two different rules and therefore sent to two different providers. The root web.config file doesn't include any rules, so if you want any Web events actually recorded, you'll need to add at least one rule to your web.config file.

Listing 7-7 is an example of a set of rules that sends all security audits to a security database, while sending all events to a statistical database (these providers were defined earlier in this chapter).

Listing 7-7. Defining health monitoring rules in web.config

<!-- web.config --> <healthMonitoring enabled="true">   <!-- ... -->   <rules>     <add name="Log all security audits to the security database"          eventName="All Audits"          provider="SecuritySqlProvider" />     <add name="Send a copy of all events to the statistics database"          eventName="All Events"          provider="StatisticsSqlProvider" />   </rules> </healthMonitoring> 




Essential ASP. NET 2.0
Essential ASP.NET 2.0
ISBN: 0321237706
EAN: 2147483647
Year: 2006
Pages: 104

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net