以编程方式访问 HealthMonitoring Provider 设置

发布于 2024-08-10 03:04:29 字数 1326 浏览 7 评论 0原文

我已经在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

断念 2024-08-17 03:04:29

在 C# 中:

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

section.Providers[3].Parameters["to"] 返回 "[电子邮件受保护]"

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

In C#:

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

section.Providers[3].Parameters["to"] returns "[email protected]".

(3 assumes that the providers list wasn't cleared in web.config.)

垂暮老矣 2024-08-17 03:04:29

我将 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]

还在原地等你 2024-08-17 03:04:29

根据 AUSteve 的回答,我使用了下面的代码。

Dim xmldoc As New System.Xml.XmlDocument
xmldoc.Load(HttpContext.Current.Server.MapPath("Web.config"))
Dim xmlnsManager As System.Xml.XmlNamespaceManager = New System.Xml.XmlNamespaceManager(xmldoc.NameTable)
xmlnsManager.AddNamespace("nc", "http://schemas.microsoft.com/.NetConfiguration/v2.0")

Dim emailTo As String = xmldoc.SelectSingleNode("/configuration/system.web/healthMonitoring/providers/add", xmlnsManager).Attributes("to").Value.ToString

Based on AUSteve's answer I used the below code.

Dim xmldoc As New System.Xml.XmlDocument
xmldoc.Load(HttpContext.Current.Server.MapPath("Web.config"))
Dim xmlnsManager As System.Xml.XmlNamespaceManager = New System.Xml.XmlNamespaceManager(xmldoc.NameTable)
xmlnsManager.AddNamespace("nc", "http://schemas.microsoft.com/.NetConfiguration/v2.0")

Dim emailTo As String = xmldoc.SelectSingleNode("/configuration/system.web/healthMonitoring/providers/add", xmlnsManager).Attributes("to").Value.ToString
七度光 2024-08-17 03:04:29

您可以使用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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文