Asp. net use HealthMonitor attribute usage _ practical skill

Source: Internet
Author: User
Tags time interval

In asp.net 2.0, you can use the healthmonitoring property to monitor events. The Healthmonitoring property is a method based provider, where you can construct your own provider. With the healthmonitoring attribute, we can create our own providers for different data sources, such as event logs, SQL Server, or even for ourselves by inheriting webeventprovider classes, such as recording the wrong language, succeeding events, and so on. In this article, I'm going to introduce a Web application that configures a SQL Server to monitor the wrong language and send mail to someone's e-mail address. First, take a look at the healthmonitoring program fragment in Web.config, where you can build the event you want to use.

<buffermodes> </bufferModes>
<providers> </providers>
<eventmappings> </eventMappings>
<profiles> </profiles>
<rules> </rules>

If you look at the

Buffermodes, where you can define the size of a provider buffer.

Providers, here is a description of the Providers handling the event.

Eventmappings, here you can draw an event name related to the friendly event type.

Profiles, this defines a set of parameter sets that can be used to configure events.

Rules, here's a picture of the providers event.

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

Before continuing, here is a list of some providers included in 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, and the names tell us what they do. Also mention that SqlWebEventProvider relies on SQL Server to store events in the Aspnet_web_event table. In order to install this database, you must run the Aspnet_regsql.exe Wizard in the Framework folder.

Now configure the program for SQL Server provider that has a logon error and sends an e-mail message.

Here is an example of using SqlWebEventProvider and Simplemailwebeventprovider to save the wrong language event.

<bufferModes>
<add name= "Critical Notification" maxbuffersize= "maxflushsize=" urgentflushthreshold= "1" Regularflushinterval= "Infinite" urgentflushinterval= "00:01:00" maxbufferthreads= "1"/>

<add name= "Analysis" maxbuffersize= "1000" maxflushsize= "100" urgentflushthreshold= "
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>

In this example, you use SQL provider to log all the error-language events and use mail provider to send a message when the Web request Error event is awakened.

Here are some of the events that were published with ASP. NET 2.0:

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 paint a provider. You can also create your own events inherited through the WebBaseEvent class.

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

Try
{
//....
}

catch (Exception e)
{
if (healthmonitoringmanager.enabled)
{
Webbaseevent.raise (New Weberrorevent ("My Error message", NULL, 5000, E));
}
}

Or

if (healthmonitoringmanager.enabled)
{
Weberrorevent event = new Weberrorevent ("My error message", NULL, 5000, E);
Event. Raise ();
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.