`
leonardleonard
  • 浏览: 777086 次
社区版块
存档分类
最新评论

ASP.NET中用healthMonitor属性用

阅读更多
在ASP.NET 2.0中,可以使用healthMonitoring属性监测事件。healthMonitoring属性是一个基于方法的provider,在这里可以构造自己的provider。利用healthMonitoring属性,我们可以诸如记录错语、成功的事件等,对不同的数据源,如事件日志,Sql Server甚至对于自己通过继承WebEventProvider类创建自己的providers。在此文章中,我打算介绍配置一个监测SqlServer错语的并且对某人的电子信箱地址发送邮件的web应用程序。首先,看一下在web.config中的healthMonitoring程序片段,在此可以建立将要用到的事件。

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

  如果看一下<healthMonitoring>元素,就可以判断是否可以将设置属性为有效或无效,也可以指定对WebHeaderBeatEvent被唤醒的时间间隔。healthMonitoring有5个孩子。

  bufferModes,在此可以定义一个Provider的缓冲区大小。

  Providers,在此说明处理事件的Providers。

  eventMappings, 在此可以画出与友好事件类型相关的事件名称。

  profiles, 在此定义一个可以用来配置事件的参数集集合。

  rules, 在此画出Providers的事件图。

  可以阅读更多含在VS 2550文档中的关于这些元素的东西。

  在继续之前,这里有一份含ASP.NET中的一些Providers清单:

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

  不需要解释这些,名字告诉我们它们是干什么的。还要提一下SqlWebEventProvider依靠Sql server而工作,它将事件存储在aspnet_Web_Event表。为了安装此数据库,必须运行位于framework文件夹中的aspnet_regsql.exe向导。

  现在,配置对Sql server provider有登录错语并且发送一个电子邮件而产生错误的程序。

  下面是一个使用SqlWebEventProvider和SimpleMailWebEventProvider来存错语事件的例子。

<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>

  在此例子中,使用Sql provider来记录所有错语事件,并且当Web请求错误事件被唤醒时使用mail provider来发送一个消息。

  这里有一些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

  可以使用这些事件来对一个provider画图。也可以创建通过WebBaseEvent类继承来的自己的事件。

  为自动唤醒一个事件,可以使用WebBaseEvent类的唤醒方法:

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();
}

 
分享到:
评论

相关推荐

    ASP.NET中用healthMonitor属性用法

    在ASP.NET 2.0中,可以使用healthMonitoring属性监测事件。healthMonitoring属性是一个基于方法的provider,在这里可以构造自己的provider。利用healthMonitoring属性,我们可以诸如记录错语、成功的事件等,对不同...

    asp.net中用web chart做各类统计图

    一个完整的在asp.net中做Web chart的例子,包括第三方chart控件,以及完整的代码调用和使用. 绝对是好资源,C#,.NET,ASP.NET,Web,Web Chart,Chart

    Asp.net Treeview 控件常用属性.

    Asp.net Treeview 控件常用属性.

    ASP.NET 中用TreeView实现树目录的实例

    ASP.NET 中用TreeView实现树目录的实例

    asp.net 中用 Ajax实现 treeview

    asp.net 中用 Ajax实现 treeview,不用刷新

    ASP.NET中用TreeView控件实现树目录的方法研究

    目前IT市场大部分是用Microsoft Visual Studio?NET采开发ASP.NET Web应用程序的。其包含了四种IEWeb控件,这些Web控件通过提供Web访问者熟悉的用户界面,增强了ASP.NETWeb页面。Tree View Web控件就是其中之一。...

    ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典

    ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP...

    asp.net中用C#写的在线考试系统

    asp.net中用C#写的在线考试系统,动态网页,经测试可直接使用,实现随机抽题,在线答题、评分等功能

    web开发ASP.NET中用FLASH控件

    web开发ASP.NET中用FLASH控件 将控件添加到工具栏中 然后拖出来用即可

    ASP.net 中用C#调用Java web service 图解教程

    ASP.net 中用C#调用Java web service 图解教程

    asp.net教程 ASP.NET 参考手册

    在 W3School,我们提供完整的 ASP.NET 参考手册,其中包括内建对象和组件,以及它们的属性和方法。 ASP.NET 实例 ASP.NET 实例 一系列的 ASP.NET 实例。 内容目录 ASP.NET 简介 本章解释 ASP.NET 的概念。 ASP...

    asp.net的ppt

    asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程...

    ASP.net实战项目

    ASP.net实战项目ASP.net实战项目ASP.net实战项目ASP.net实战项目ASP.net实战项目ASP.net实战项目ASP.net实战项目ASP.net实战项目ASP.net实战项目ASP.net实战项目ASP.net实战项目ASP.net实战项目ASP.net实战项目ASP...

    asp.net 获取文件属性

    asp.net 获取文件属性! 很值得下载看看!资源免费,大家分享!!

    asp.net经典聊天室

    asp.net经典聊天室asp.net经典聊天室asp.net经典聊天室asp.net经典聊天室asp.net经典聊天室asp.net经典聊天室asp.net经典聊天室asp.net经典聊天室asp.net经典聊天室asp.net经典聊天室asp.net经典聊天室asp.net经典...

    asp.net排课系统

    asp.net 排课 系统asp.net 排课 系统asp.net 排课 系统asp.net 排课 系统asp.net 排课 系统asp.net 排课 系统asp.net 排课 系统asp.net 排课 系统asp.net 排课 系统

    ASP.NET操作echarts

    使用ASP.NET与echarts进行数据交互,利用C#中的ASP.NET作为后台产生数据,通过Ajax作为前端定时与后端进行数据交互

    ASP.NET 4.5入门经典:涵盖C#和VB.NET(第7版) 源码

    《ASP.NET 4入门经典:涵盖C#和VB.NET(第6版)》循序渐进,逐步讲解了如何使用ASP.NET 4构建内容丰富的Web站点,并提供了大量使用C#和VB的示例。通过实际动手练习,您将学到关于构建Web站点的第一手信息,同时能够...

    北大青鸟课件-使用ASP.NET构建动态网站(附实例源码0)

    《使用ASP.NET构建动态网站》课程目标: 1.了解 .NET 框架 2.会使用VS2008 进行ASP.NET 程序开发 3.掌握C# 语言的基本语法 4.掌握常用ASP.NET控件的使用 5.掌握使用ADO.NET 进行数据库程序开发 6.掌握ASP.NET常用...

Global site tag (gtag.js) - Google Analytics