ASP.NET is used with the healthMonitor attribute

  • 2020-05-05 11:09:56
  • OfStack

In ASP.NET 2.0, you can use the healthMonitoring attribute to monitor events. The healthMonitoring attribute is a method based provider where you can construct your own provider. Using the healthMonitoring attribute, we can create our own providers by inheriting the WebEventProvider class, for example, by logging errors, successful events, etc., for different data sources, such as event logs, Sql Server, and even for ourselves. In this article, I'm going to show you how to configure an web application that detects SqlServer misspellings and sends messages to someone's E-mail address. First, take a look at the healthMonitoring program fragment in web.config, where you can set up the events to be used.

< healthMonitoring Enabled="true|false" heartBeatInterval="time interval" >
< bufferModes > ... < /bufferModes >
< providers > ... < /providers >
< eventMappings > ... < /eventMappings >
< profiles > ... < /profiles >
< rules > ... < /rules >
< /healthMonitoring >

If you look at < healthMonitoring > Element to determine whether the setting property can be made valid or invalid, or to specify the time interval for WebHeaderBeatEvent to be awakened. healthMonitoring has five children.

bufferModes, where you can define a buffer size for Provider.

Providers, which specifies Providers for handling events.

eventMappings, where you can draw the event name associated with the friendly event type.

profiles, which defines a collection of parameter sets that can be used to configure events.

rules, draw the Providers event graph here.

You can read more about these elements in the VS 2550 documentation.

Before proceeding, here is a list of some Providers from ASP.NET:

System.Web.Management.MailWebEventProvider
System.Web.Management.SimpleMailWebEventProvider
System.Web.Management.TemplatedMailWebEventProvider
System.Web.Management.TraceWebEventProvider
System.Web.Management.EventLogWebEventProvider
System.Web.Management.SqlWebEventProvider
System.Web.Management.WmiWebEventProvider

There's no need to explain this, the names tell us what they do. It should also be mentioned that SqlWebEventProvider works on Sql server, which stores events in aspnet_Web_Event table. To install this database, you must run the aspnet_regsql.exe wizard in the framework folder.

Now, configure the program that has a login error to Sql server provider and sends an email that generates an error.

The following is an example of using SqlWebEventProvider and SimpleMailWebEventProvider to save a misspelled event.

< healthMonitoring enabled="true" heartBeatInterval="0" >
< bufferModes >
< add name="Critical Notification" maxBufferSize="100" maxFlushSize="20"urgentFlushThreshold="1" regularFlushInterval="Infinite" urgentFlushInterval="00:01:00" maxBufferThreads="1"/ >

< add name="Analysis" maxBufferSize="1000" maxFlushSize="100" urgentFlushThreshold="100"
regularFlushInterval="00:05:00" urgentFlushInterval="00:01:00" maxBufferThreads="1"/ >

< /bufferModes >
< providers >

< add name="CriticalMailEventProvider" type="System.Web.Management.SimpleMailWebEventProvider, System.Web ..." from=info@nsquared2.net to=fnormen@hotmail.com priority="High" bodyHeader="Warning!"
bodyFooter="Please investigate ASAP." subjectPrefix="Action required." buffer="true" bufferMode="Critical Notification" maxEventLength="4096" maxSize="4096" maxMessagesPerNotification="1"/ >

< add name="SqlWebEventProvider" type="System.Web.Management.SqlWebEventProvider, System.Web ..."
connectionStringName="LocalSqlServer" maxEventDetailsLength="1073741823" buffer="true"
bufferMode="Analysis"/ >

< /providers >

< eventMappings >

< add name="All Errors" type="System.Web.Management.WebBaseErrorEvent, System.Web ..."/ >
< add name="Request Processing Errors" type="System.Web.Management.WebRequestErrorEvent, System.Web .../ >

< /eventMappings >

< profiles >

< add name="Default" minInstances="1" maxLimit="Infinite" minInterval="00:10:00"/ >

< /profiles >

< rules >

< add name="All Errors Default" eventName="All Errors" provider="SqlWebEventProvider" profile="Default"
minInterval="00:00:30"/ >

< add name="Request Processing Errors" eventName="Request Processing Errors" provider="CriticalMailEventProvider" profile="Default"/ >

< /rules >

< /healthMonitoring >

In this example, Sql provider is used to record all the error events, and mail provider is used to send a message when Web requests the error event to be awakened.

Here are some ASP.NET 2.0 releases:

System.Web.Management.WebBaseEvent
System.Web.Management.WebHeartBeatEvent
System.Web.Management.WebApplicationLifetimeEvent
System.Web.Management.WebRequestEvent
System.Web.Management.WebBaseErrorEvent
System.Web.Management.WebErrorEvent
System.Web.Management.WebRequestErrorEvent
System.Web.Management.WebAuditEvent
System.Web.Management.WebFailureAuditEvent
System.Web.Management.WebSuccessAuditEvent
System.Web.Management.WebManagementEvent
System.Web.Management.WebViewStateFailureAuditEvent
System.Web.Management.WebAuthenticationFailureAuditEvent
System.Web.Management.WebAuthenticationSuccessAuditEvent

You can use these events to plot an provider. You can also create your own events inherited through the WebBaseEvent class.

To automatically wake up an event, you can use the wake method of the WebBaseEvent class:

try
{
/ /...
}

catch(Exception e)
{

if (HealthMonitoringManager Enabled) The & # 123;
WebBaseEvent.Raise(new WebErrorEvent("My Error message", null, 5000, e));
The & # 125;
}

or:

if (HealthMonitoringManager.Enabled)
{
WebErrorEvent event = new WebErrorEvent("My error message", null, 5000, e);
event. Raise ();
}
 


Related articles: