asp.net - 以编程方式访问 HealthMonitoring Provider 设置

标签 asp.net configuration health-monitoring

我已经在 web.config 中设置了 ASP.Net 运行状况监控:

<healthMonitoring enabled="true">
<providers>
<clear />
<add name="CriticalMailEventProvider" type="System.Web.Management.SimpleMailWebEventProvider"
from="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0d6c7d7d487f7f627f7e4d607465627e79236e6260" rel="noreferrer noopener nofollow">[email protected]</a>" to="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b8d5ddf8d5c1d0d7cbcc96dbd7d5" rel="noreferrer noopener nofollow">[email protected]</a>"
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")”的所有其他属性也是如此。
我如何访问提供商的设置?

最佳答案

在 C# 中:

HealthMonitoringSection section = WebConfigurationManager.GetWebApplicationSection("system.web/healthMonitoring") as HealthMonitoringSection;

section.Providers[3].Parameters["to"] 返回 "[email protected] "

(3 假定 web.config 中未清除提供程序列表。)

关于asp.net - 以编程方式访问 HealthMonitoring Provider 设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1684722/

相关文章:

c# - 使用文本框上的 OnChange 事件进行简单显示

Javascript 发送 Json 数据

c# - 如何使用 itextsharp 并排放置两个表

cakephp - 设置 CakePHP 3 插件测试

.net-core - 错误 UseHealthChecksUI 遇到意外字符

docker - docker(1.12) 容器的健康检查命令(不在 Dockerfile 中!)

javascript - 在 Ajax 成功函数中将参数传递给 javascript 函数?

linux - 找不到包 Libval​​a

javascript - 无法连接 Node-mysql

twitter - ODL的推文元语法