我在 web.config 中设置了 ASP.Net 健康监控:
<healthMonitoring enabled="true">
<providers>
<clear />
<add name="CriticalMailEventProvider" type="System.Web.Management.SimpleMailWebEventProvider"
from="appErrors@myhost.com" to="me@myhost.com"
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 集合包含预期的键,但值是“Nothing”,“Properties(“to”)的所有其他属性也是如此)”。
如何访问 Provider 的设置?