我已经在 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/