gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 07:02:07 25 4
gpt4 key购买 nike

我已经在 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 集合包含预期的键,但 Value 是“Nothing”,“Properties(“to”)”的所有其他属性也是如此。
如何访问提供程序的设置?

最佳答案

在 C# 中:

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

section.Providers[3].Parameters["to"] 返回 "me@myhost.com" .

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com