以编程方式访问 HealthMonitoring Provider 设置
我已经在 web.config 中设置了 ASP.Net 运行状况监控:
<healthMonitoring enabled="true">
<providers>
<clear />
<add name="CriticalMailEventProvider" type="System.Web.Management.SimpleMailWebEventProvider"
from="[email protected]" to="[email protected]"
bodyHeader="Application Error!" bodyFooter="Please investigate ASAP."
subjectPrefix="ERROR: " buffer="true" bufferMode="Critical Notification"
maxEventLength="8192" maxMessagesPerNotification="1"
/>
</providers></healthMonitoring>
并且我正在尝试在代码中读取此提供程序的配置:
Dim HealthMonitoring As System.Web.Configuration.HealthMonitoringSection
Dim ToAddress As String
HealthMonitoring = CType(WebConfigurationManager.GetWebApplicationSection("system.web/healthMonitoring"), HealthMonitoringSection)
ToAddress = HealthMonitoring.Providers(0).ElementInformation.Properties("to").Value.ToString
[注意:不是实际的生产代码,是硬编码的 &为简洁起见]
问题:虽然 ElementInformation.Properties 集合包含预期的键,但 Value 为“Nothing”,“Properties("to")”的所有其他属性也是如此。
我如何访问提供商的设置?
I have set up ASP.Net health monitoring in web.config:
<healthMonitoring enabled="true">
<providers>
<clear />
<add name="CriticalMailEventProvider" type="System.Web.Management.SimpleMailWebEventProvider"
from="[email protected]" to="[email protected]"
bodyHeader="Application Error!" bodyFooter="Please investigate ASAP."
subjectPrefix="ERROR: " buffer="true" bufferMode="Critical Notification"
maxEventLength="8192" maxMessagesPerNotification="1"
/>
</providers></healthMonitoring>
And I am attempting to read the configuration of this provider in code:
Dim HealthMonitoring As System.Web.Configuration.HealthMonitoringSection
Dim ToAddress As String
HealthMonitoring = CType(WebConfigurationManager.GetWebApplicationSection("system.web/healthMonitoring"), HealthMonitoringSection)
ToAddress = HealthMonitoring.Providers(0).ElementInformation.Properties("to").Value.ToString
[Note: not actual production code, hard-coded & condensed for brevity]
The problem: While the ElementInformation.Properties collection contains the keys as expected, the Value is "Nothing" and so are all other properties of "Properties("to")".
How can I access the settings of the Provider?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 C# 中:
section.Providers[3].Parameters["to"] 返回 "[电子邮件受保护]"。
(3 假设 web.config 中未清除提供程序列表。)
In C#:
section.Providers[3].Parameters["to"] returns "[email protected]".
(3 assumes that the providers list wasn't cleared in web.config.)
我将 web.config 文件作为 XML 文档读取,并使用通过 XPath 选择的节点:configuration/system.web/healthMonitoring/providers/*[@name]
I've resorted to reading the web.config file as an XML document and using the nodes selected with the XPath: configuration/system.web/healthMonitoring/providers/*[@name]
根据 AUSteve 的回答,我使用了下面的代码。
Based on AUSteve's answer I used the below code.
您可以使用Initialize 方法来访问您在web.config 中指定的属性。只需访问 NameValueCollection(并在调用 base.Initialize 之前将其删除您的自定义属性)
本文展示了一个 C# 实现:http://www.tomot.de/en-us/article/6/asp .net/如何创建发送电子邮件的自定义健康监控提供程序
You can use the Initialize method to access the attributes you specified in the web.config. Just access the NameValueCollection (and remove it your custom attributes before base.Initialize is being called)
This article shows a C# implementation: http://www.tomot.de/en-us/article/6/asp.net/how-to-create-a-custom-healthmonitoring-provider-that-sends-e-mails