我正在寻找有关如何为 ASP.Net Healthmonitoring 创建和使用自定义提供程序的演练。
到目前为止,我只与生成错误电子邮件的电子邮件提供商合作过。基本上我想做同样的事情,但更灵活:
我想以允许我访问事件的方式使用 HealthMonitoring 功能(我不想在 global.asax 中使用 Application_OnError 事件),即像“OnNewHealthMonitoringEntry”一样抛出电子邮件中提供的所有信息,以运行自定义代码。
编辑:
基于此处提供的源代码http://www.asp.net/general/videos/how-do-i-create-a-custom-provider-for-logging-health-monitoring-events我能够构建我自己的自定义提供程序并实现它。现在我想添加一些新属性来配置我的自定义提供程序。这是 web.config 的样子:
<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>
如果我尝试向提供者添加一个属性,就像这样
<providers>
<add name="FileEventProvider" buffer="true" bufferMode="Log Notification" foo="bar" type="healthmonitoringtest.FileHealthMonitorEventProvider"/>
</providers>
我会收到一条错误消息:
System.Web.dll 中发生“System.Configuration.ConfigurationErrorsException”类型的异常,但未在用户代码中处理附加信息:FileEventProvider 配置中的意外属性 foo。
是否可以将自定义提供程序所需的配置存储在 healthMonitoring 部分附近?我想我可以将设置包含到 appSettings 节点中,但我想以某种方式使用属性(在 healthMonitoring 节点内)对其进行配置。那可能吗?
Edit2:您可以看看这篇文章:http ://www.tomot.de/en-us/article/6/asp.net/how-to-create-a-custom-healthmonitoring-provider-that-sends - 电子邮件