如何编写和配置ASP.Net Healthmonitoring自定义提供? [英] How to write and configure a custom provider for ASP.Net Healthmonitoring?

查看:138
本文介绍了如何编写和配置ASP.Net Healthmonitoring自定义提供?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找关于如何创建和使用ASP.Net Healthmonitoring自定义提供程序的演练。

I'm looking for a walkthrough on how to create and use a custom provider for ASP.Net Healthmonitoring.

到目前为止,我只上的错误产生电子邮件的电子邮件提供商合作。基本上我想这样做,但有更多的灵活性:结果
我想用HealthMonitoring功能(我不希望使用在Global.asax的Application_OnError事件)的方式,让我有机会获得一个事件,获取引发像OnNewHealthMonitoringEntry,并且在提供的所有信息电子邮件,运行自定义code。

So far I've only worked with the e-mail provider that generates e-mails on errors. Basically I want to do the same, but with more flexibility:
I want to use the HealthMonitoring features (I don't want to use the Application_OnError event in the global.asax) in a way that allows me have access to an event, that gets thrown like "OnNewHealthMonitoringEntry" with all the information provided in the e-mail, to run custom code.

编辑:结果
基于此处提供<一个源$ C ​​$ C href=\"http://www.asp.net/general/videos/how-do-i-create-a-custom-provider-for-logging-health-monitoring-events\" rel=\"nofollow\">http://www.asp.net/general/videos/how-do-i-create-a-custom-provider-for-logging-health-monitoring-events我是能够建立自己的自定义提供者和执行它。现在,我想添加一些新的属性来配置我的自定义提供。
这里是web.config中是什么样子:


Based on the source code provided here http://www.asp.net/general/videos/how-do-i-create-a-custom-provider-for-logging-health-monitoring-events I was able to build my own custom provider and implement it. Now I want to add some new attributes to configure my custom provider. Here is what the web.config looks like:

<healthMonitoring>
    <bufferModes>
        <add name="Log Notification" maxBufferSize="1" maxFlushSize="1" urgentFlushThreshold="1" regularFlushInterval="Infinite" urgentFlushInterval="00:00:10"/>
    </bufferModes>
    <providers>
        <add name="FileEventProvider" buffer="true" bufferMode="Log Notification" type="healthmonitoringtest.FileHealthMonitorEventProvider"/>
    </providers>
    <profiles>
        <add name="Custom" minInstances="1" maxLimit="Infinite" minInterval="00:00:00"/>
    </profiles>
    <rules>
        <add name="File Event Provider" eventName="All Errors" provider="FileEventProvider" profile="Custom"/>
    </rules>
</healthMonitoring>

如果我尝试将属性添加到供应商,这样

If I attempt to add an attribute to the provider, like this

<providers>
    <add name="FileEventProvider" buffer="true" bufferMode="Log Notification" foo="bar"  type="healthmonitoringtest.FileHealthMonitorEventProvider"/>
</providers>

我会得到一个错误说:

I'll get an error saying:

类型的例外
  System.Configuration.ConfigurationErrorsException
  发生在System.Web.dll中,但没有
  在用户code附加处理
  信息:意外的属性富
  在的配置
  FileEventProvider。

An exception of type 'System.Configuration.ConfigurationErrorsException' occurred in System.Web.dll but was not handled in user code Additional information: Unexpected attribute foo in the configuration of the FileEventProvider.

时可以存储必要的接近healthMonitoring节自定义提供的配置?我想我可以包括设置成的appSettings节点,但我想用某种方式的属性配置它(healthMonitoring节点内)。这可能吗?

Is it possible to store configuration necessary for custom provider close to the healthMonitoring section? I guess I could include the settings into the appSettings node, but I'd like to configure it somehow with attributes (inside the healthMonitoring node). Is that possible?

EDIT2
你可以看看这篇文章:<一href=\"http://www.tomot.de/en-us/article/6/asp.net/how-to-create-a-custom-healthmonitoring-provider-that-sends-e-mails\" rel=\"nofollow\">http://www.tomot.de/en-us/article/6/asp.net/how-to-create-a-custom-healthmonitoring-provider-that-sends-e-mails

推荐答案

以下系列文章将带您通过使用健康监测系统高达创建自定义事件的基本知识。

The following series of articles will take you through the basics of using the Health Monitoring System upto creating Custom Events.

那么下面的<一个href=\"http://www.asp.net/general/videos/how-do-i-create-a-custom-provider-for-logging-health-monitoring-events\"相对=nofollow>26分钟影片将引导您完成创建记录事件到一个基于文本的日志文件自定义提供。

Then the following 26 minute video will take you through creating a custom provider that records events to a text-based log file.

基于注释更新

看你的更新,并使用反射来看看源为您基于您的自定义提供商,我已经找到了 BufferedWebEventProvider 类初始化方法 BufferedWebEventProvider 确实在一查到底,看看是否有它不承认任何属性。这是因为他们被分配到属性或的 BufferedWebEventProvider 字段从配置参数的NameValueCollection尽快移除值来实现。然后进行检查,完成以查看是否配置参数是空的,如果不是,这意味着有补充额外的属性,这将导致一个异常被抛出。

Looking at your update and using Reflector to look at the source for the BufferedWebEventProvider class that you base your custom provider on, I have found that the Initialize method in BufferedWebEventProvider does a check at the end to see if there are any attributes that it doesn't recognize. This is done by removing values from the config NameValueCollection parameter as soon as they are assigned to the properties or fields of the BufferedWebEventProvider. Then a check is done to see if the config parameter is empty and if not that means that there are extra attributes added, which causes an exception to be thrown.

至于如何解决这个问题,一种选择是:

As to how to fix this problem, one option is to:


  1. 将调用base.Initialize的方法结束

  2. 只要你将它们分配给变量就像提供商删除附加属性一样。

像下面的内容将工作:

public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
    {
        foo = config["foo"];
        if (String.IsNullOrEmpty(foo))
        {
            // You can set a default value for foo
        }

        //remove foo from the config just like BufferedWebEventProvider with the other
        //attributes. Note that it doesn't matter if someone didn't proivde a foo attribute
        //because the NameValueCollection remains unchanged if you call its Remove method
        //and the name doesn't exist.
        config.Remove("foo");

        base.Initialize(name, config);
    }

希望这个作品送给你。

Hopefully this works out for you.

这篇关于如何编写和配置ASP.Net Healthmonitoring自定义提供?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆