In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to realize health monitoring in ASP.NET project development". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian slowly and deeply to study and learn "how to realize health monitoring in ASP.NET project development" together!
Health Monitoring is a new feature added in ASP.NET 2.0 and later. It allows developers to monitor the application for unusual events. And monitoring application startup, shutdown, validation, etc. have corresponding events to monitor. And we can create custom events to monitor specific parts of the application. We can also configure in Health Monitoring whether exceptions in the application are logged in the system log or Sql Server, or sent as an Email. The most important point is that we can implement strong exception handling strategies (and similar Enterprise Application Blocks, which we'll talk about later) with little or no code as long as we configure them.
Similarly, we add configuration to web.config and healthMonitoring/> node to system.web node:
Disabled by default, we enable it should be as follows:
Health Monitoring in ASP.NET Project Development Code1
﹤healthMonitoring enabled="true﹥ ﹤eventMappings﹥﹤/eventMappings﹥ ﹤providers﹥﹤/providers﹥ ﹤rules﹥..﹤/rules﹥ ﹤profiles﹥..﹤/profiles﹥ ﹤bufferModes﹥..﹤/bufferModes﹥ ﹤/healthMonitoring﹥
Let's take a look at some of the configurations under this node:
The eventMappings node registers event classes by specifying event types. In other words, to specify which events we want to listen for in the application, the following configuration:
﹤eventMappings﹥ ﹤clear /﹥ ﹤add name="CustomException" type="System.Web.Management.WebBaseErrorEvent" /﹥ ﹤/eventMappings﹥
The "name" attribute in the front is our own friendly name for the event that follows. From the literal meaning of eventMappings>, we can also know: event mapping.
The "type" that follows is the event we want to listen for in the program. As mentioned earlier, we can listen for many events: system startup, shutdown, validation failure, etc.
As seen above: "System.Web.Management.WebBaseErrorEvent" is the base class for all events. There are many subclasses:
Web Application Lifetime Event--something that triggers during the running of the application, e.g. when the application is open and closed
WebAuthenticationFailureAuditEvent--is triggered when ASP.NET authentication fails
WebAuthenticationSuccessAuditEvent--Triggered when authentication succeeds
WebRequestErrorEvent--Triggered when a request error occurs
In addition, we can customize some classes, derived from base classes.
Once we have identified the event to listen to, we select the provider of the event, that is, after the event is triggered, we record the information of the event there.
The configuration is as follows:
﹤providers﹥ ﹤clear /﹥ ﹤add name="EventLogProvider" type="System.Web.Management.EventLogWebEventProvider" /﹥ ﹤/providers﹥
The same as before: System.Web.Management.EventLogWebEventProvider is a base class with many subclasses that allow us to log exceptions in databases such as sql, system logs, etc.:
SqlWebEventProvider--A provider that logs exception information to the database
SimpleMailEventProvider--A provider that sends exception messages via Email
There are some, see MSDN.
Well, here, we have chosen the events to listen to, such as WebApplicationLifetimeEvent, WebRequestErrorEvent; and we are also ready to send the exception system through Email, we have chosen SimpleMailEventProvider, and we also want to record the exception to the database, we have chosen SqlWebEventProvider. Then our configuration is as follows:
Health Monitoring in ASP.NET Project Development Code2
﹤healthMonitoring enabled="true﹥ ﹤eventMappings﹥ ﹤clear /﹥ ﹤add name="CustomException" type="System.Web.Management.WebApplicationLifetimeEvent" /﹥ ﹤add name="AnotherException" type="System.Web.Management.WebRequestErrorEvent" /﹥ ﹤/eventMappings﹥ ﹤providers﹥ ﹤clear /﹥ ﹤add name="EmailProvider" type="System.Web.Management.SimpleMailEventProvider" /﹥ ﹤add name="SqlProvider" type="System.Web.Management.WebRequestErrorEvent" /﹥ ﹤/providers﹥ ﹤/healthMonitoring﹥
Note: The "name" attribute in the providers node is also our own friendly name.
Well, the definition of the definition is good, and now it still can't work according to our requirements, that's because we still lack a "rule":
As follows:
Health Monitoring in ASP.NET Project Development Code3
﹤rules﹥ ﹤clear /﹥ ﹤add name="Unhandled Exceptions Rule" eventName="Unhandled Exceptions" provider="EventLogProvider" profile="Default" minInstances="1" maxLimit="Infinite" minInterval="00:00:00" /﹥ ﹤/rules﹥
In fact, rules is to put up the events we defined earlier to listen to and the corresponding provider objects:
﹤rules﹥ ﹤clear /﹥ ﹤add name="MyRules1" eventName="CustomException" provider="EmailProvider" profile="Default" minInstances="1" maxLimit="Infinite" minInterval="00:00:00" /﹥ ﹤/rules﹥
Note the name attribute above. As before, we are just giving this rule a name. eventName is the event name defined previously, such as "CustomException",provider is the previously defined "EmailProvider", this rule means that EmailProvider handles exception information of CustomException. The rest is the same.
*** One thing to note is that if we decide to send Email, we also need to configure the node:
﹤system.net﹥ ﹤mailSettings﹥ ﹤smtp deliveryMethod="PickupDirectoryFromIis"﹥ ﹤network defaultCredentials="true" host="127.0.0.1" /﹥ ﹤/smtp﹥ ﹤/mailSettings﹥ ﹤/system.net﹥
That'll do.
Thank you for reading, the above is "ASP.NET project development in health monitoring how to achieve" the content, after learning this article, I believe we have a deeper understanding of ASP.NET project development in health monitoring how to achieve this problem, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.