Customizing
Event Analysis:
After
deployment to make the life of administrators easy, ASP.NET provides the
following facilities:
* Monitor Live
ASP.NET Application individually or across Web Farm.
* Diagnose an
application that appears to be failing.
* Log events which
are not exception but useful for investigation.
Ways
to notify Administrator about the errors:
Through
Event Log,
E-Mail notification, Event stored in database.
Other
helpful events could be:
1. Starting or Ending a Web Application
2. Successful and unsuccessful
authentication attempts
3. ASP.NET errors
4. Custom Application Events
In
ASP.NET All Errors and Failure Audits events are enabled.
Other
ASP.NET Event Providers and Web Events are:
ASP.NET
Event Provider:
|
Event Provider
|
Description
|
|
EventLogWebEventProvider
|
Writes Web event data to the Windows
event log. By default, this provider is configured to write all errors to the
Windows event log. Security operation errors are logged under the event name
Failure Audits and all other errors are logged under the event name All
Errors.
|
|
SqlWebEventProvider
|
Logs Web event data to a Microsoft SQL
Server database. By default, this provider logs data to the SQL Server
Express database in the Web application’s App_Data folder.
|
|
WmiWebEventProvider
|
Passes Web events to Windows Management
Instrumentation (WMI), converting them to WMI events.
|
|
SimpleMailWebEventProvider and TemplatedMailWebEventProvider
|
Sends an e-mail message when Web events
are raised.
|
|
TraceWebEventProvider
|
Passes event data to the ASP.NET page
tracing system. You can use the events to debug an application and perform
capacity and performance analysis.
|
To
create Custom Event Providers inherit from WebEventProvider or BufferedWebEventProvider.
For more details on Provider Visit:
http://msdn2.microsoft.com/en-us/ms228095.aspx
ASP.NET
Web Events
Health
monitoring process using WMI:
Configuring
Health-Monitoring Events:
Health
Monitoring is configured in web.config and have the following major elements:
<bufferModes>:Events may raise
in a frequent manner causing web application to remain busy in
Health-Monitoring. <bufferModes> allows Health-Monitoring Events to be
processed and dispatched in batches.
<provider>: By default it
contains EventLogProvider, LocalSqlServer, WmiWebEventProvider.
SimpleMailWebEventProvider, TemplatedMailWebEventProvider can be also
configured.
<profiles>: It defines how
many times an event can occur in specified time. Default (prevents more than
once in a minute) and Critical (See every event that occur) are available by
default.
<rules>: Associates Events
with EventProviders. By Default All Errors and FailureAudits à EventLogProvider.
<eventMappings>: Associates event
name with the class that implements them. All Errors ß WebBaseEvent and Failure
Audits ß WebFailureAuditEvent.
Sample
<healthMonitoring
heartbeatInterval="0" enabled="true">
<bufferModes>
<add name="Critical
Notification"
maxBufferSize="100"
maxFlushSize="20"
urgentFlushThreshold="1"
regularFlushInterval="Infinite"
urgentFlushInterval="00:01:00"
maxBufferThreads="1" />
<add name="Notification"
maxBufferSize="300"
maxFlushSize="20"
urgentFlushThreshold="1"
regularFlushInterval="Infinite"
urgentFlushInterval="00:01:00"
maxBufferThreads="1" />
</bufferModes>
<providers>
<add
name="EventLogProvider"
type="System.Web.Management.EventLogWebEventProvider,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"
/>
<add
ConnectionStringName="LocalSqlServer"
maxEventDetailsLength="1073741823"
buffer="false"
bufferMode="Notification"
name="SqlWebEventProvider"
type="System.Web.Management.SqlWebEventProvider,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"
/>
</providers>
<profiles>
<add
name="Default"
minInstances="1"
maxLimit="Infinite"
minInterval="00:01:00"
custom="" />
<add
name="Critical"
minInstances="1"
maxLimit="Infinite"
minInterval="00:00:00"
custom="" />
</profiles>
<rules>
<add
name="All Errors Default"
eventName="All Errors"
provider="EventLogProvider"
profile="Default"
minInstances="1"
maxLimit="Infinite"
minInterval="00:01:00"
custom="" />
<add
name="Failure Audits Default"
eventName="Failure Audits"
provider="EventLogProvider"
profile="Default"
minInstances="1"
maxLimit="Infinite"
minInterval="00:01:00"
custom="" />
</rules>
<eventMappings>
<add
name="All Events"
type="System.Web.Management.WebBaseEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"
startEventCode="0"
endEventCode="2147483647" />
<add
name="All Errors"
type="System.Web.Management.WebBaseErrorEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"
startEventCode="0"
endEventCode="2147483647" />
<add
name="All Audits"
type="System.Web.Management.WebAuditEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"
startEventCode="0"
endEventCode="2147483647" />
<add
name="Failure Audits"
type="System.Web.Management.WebFailureAuditEvent,
System.Web,Version=2.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
startEventCode="0"
endEventCode="2147483647" />
</eventMappings>
</healthMonitoring>
Providing
Custom Performance Counters:
With
.Net 2.0 Developers can easly add custom performance counter and to Update
Performance data from within your code.
Monitoring
Performace Counters:
First
Create Performance Counter and provide it with useful data.
PerformanceCounter pc = new PerformanceCounter( “ASP.NET”,
“Requests Queued”);
lblQueued.Text = pc.RawValue.ToString();
To
view performance open performance Dialog from:
Administrative
Tools
| Performance
To
Add Performace Counter from UI Go to Server Explorer, Expand the Node
R.Click the “Performance Counter” And select New Category. Provide name
and description. Click Add. Now Add counters to category.
It’s
better to add Counters Programmaticlly during Setup.
Adding
Custom Performance Counter Catogries:
Performance
Counter can be added to Existing categories, It’s recommended to define a newer
category specific to application.
To
create a Performance Counter Category with a single counter:
PerformanceCounterCategory.Create(“CategoryName”,
“CounterHelp”, PerformanceCounterCategoryType.MultiInstance, “CounterName”,
“CounterHelp”);
To
Add multiples counters to a single category Use CounterCreationDataCollection
class.
Providing
Performance Counter Data:
Performance
Data is sampled over 400 Miliiseconds. Update the Performance counter data when
changes occur.
To
Update Data create Performance Counter as you are reading it but specify False
for ReadOnly property.
PerformanceCounter pc = new PerformanceCounter(
“MyAppCountries”, “Sales”, false);
Pc.RawValue = 7;
Pc.Decrement();
Pc.Increment();
Pc.IncrementBy(3);
Pc.DecrementBy(3);