RuleSettings 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
配置 ASP.NET 事件规则。 此类不能被继承。
public ref class RuleSettings sealed : System::Configuration::ConfigurationElement
public sealed class RuleSettings : System.Configuration.ConfigurationElement
type RuleSettings = class
inherit ConfigurationElement
Public NotInheritable Class RuleSettings
Inherits ConfigurationElement
- 继承
示例
以下配置文件摘录显示了如何以声明方式指定类的属性 RuleSettings 。
<healthMonitoring>
<rules>
<add name="All Errors Default"
eventName="All Errors"
provider="EventLogProvider"
profile="Default"
minInterval="00:01:00"
/>
<add name="All Audits Default"
eventName="All Audits"
provider="SqlWebEventProvider"
profile="Default"
minInterval="00:00:30"
/>
<add name="Failure Audits Default"
eventName="Failure Audits"
provider="WmiWebEventProvider"
profile="Critical"
minInterval="00:00:30"
/>
<add name="Request Processing Errors"
eventName="Request Processing Errors"
provider="CriticalMailEventProvider"
profile="Default"
/>
<add name="Infrastructure Notifications"
eventName="Infrastructure Errors"
provider="CriticalMailEventProvider"
profile="Critical"
/>
</rules>
</healthMonitoring>
下面的代码示例演示如何创建和设置该类型的值 RuleSettings 。 此代码示例是为 HealthMonitoringSection 类提供的一个更大示例的一部分。
// Add a RuleSettings object to the Rules collection property.
RuleSettings ruleSetting = new RuleSettings("All Errors Default",
"All Errors", "EventLogProvider");
ruleSetting.Name = "All Errors Custom";
ruleSetting.EventName = "All Errors";
ruleSetting.Provider = "EventLogProvider";
ruleSetting.Profile = "Custom";
ruleSetting.MaxLimit = Int32.MaxValue;
ruleSetting.MinInstances = 1;
ruleSetting.MinInterval = TimeSpan.Parse("00:00:30");
ruleSetting.Custom = "MyEvaluators.MyCustomeEvaluator2, MyCustom.dll";
healthMonitoringSection.Rules.Add(ruleSetting);
' Add a RuleSettings object to the Rules collection property.
Dim ruleSetting As RuleSettings = new RuleSettings("All Errors Default", _
"All Errors", "EventLogProvider")
ruleSetting.Name = "All Errors Custom"
ruleSetting.EventName = "All Errors"
ruleSetting.Provider = "EventLogProvider"
ruleSetting.Profile = "Custom"
ruleSetting.MaxLimit = Int32.MaxValue
ruleSetting.MinInstances = 1
ruleSetting.MinInterval = TimeSpan.Parse("00:00:30")
ruleSetting.Custom = "MyEvaluators.MyCustomeEvaluator2, MyCustom.dll"
healthMonitoringSection.Rules.Add(ruleSetting)
下面的代码示例演示如何获取和显示该类型的值 RuleSettings 。 此代码示例是为 HealthMonitoringSection 类提供的一个更大示例的一部分。
// Display contents of the Rules collection property
Console.WriteLine(
"Rules Collection contains {0} values:", healthMonitoringSection.Rules.Count);
// Display all elements.
for (System.Int32 i = 0; i < healthMonitoringSection.Rules.Count; i++)
{
ruleSetting = healthMonitoringSection.Rules[i];
string name = ruleSetting.Name;
string eventName = ruleSetting.EventName;
string provider = ruleSetting.Provider;
string profile = ruleSetting.Profile;
int minInstances = ruleSetting.MinInstances;
int maxLimit = ruleSetting.MaxLimit;
TimeSpan minInterval = ruleSetting.MinInterval;
string custom = ruleSetting.Custom;
string item = "Name='" + name + "', EventName='" + eventName +
"', Provider = '" + provider + "', Profile = '" + profile +
"', MinInstances = '" + minInstances + "', MaxLimit = '" + maxLimit +
"', MinInterval = '" + minInterval + "', Custom = '" + custom + "'";
Console.WriteLine(" Item {0}: {1}", i, item);
}
' Display contents of the Rules collection property
Console.WriteLine( _
"Rules Collection contains {0} values:", healthMonitoringSection.Rules.Count)
' Display all elements.
For i As System.Int32 = 0 To healthMonitoringSection.Rules.Count -1
ruleSetting = healthMonitoringSection.Rules(i)
Dim name As String = ruleSetting.Name
Dim eventName As String = ruleSetting.EventName
Dim provider As String = ruleSetting.Provider
Dim profile As String = ruleSetting.Profile
Dim minInstances As Integer = ruleSetting.MinInstances
Dim maxLimit As Integer = ruleSetting.MaxLimit
Dim minInterval As TimeSpan = ruleSetting.MinInterval
Dim custom As String = ruleSetting.Custom
Dim item As String = "Name='" & name & "', EventName='" & eventName & _
"', Provider = '" & provider & "', Profile = '" & profile & _
"', MinInstances = '" & minInstances & "', MaxLimit = '" & maxLimit & _
"', MinInterval = '" & minInterval.ToString() & "', Custom = '" & custom & "'"
Console.WriteLine(" Item {0}: {1}", i, item)
Next
注解
事件规则确定哪个事件(使用哪个配置文件)触发到哪个提供程序。
构造函数
RuleSettings(String, String, String) |
使用默认设置初始化 RuleSettings 类的新实例;但名称、事件名称和提供程序是指定的。 |
RuleSettings(String, String, String, String, Int32, Int32, TimeSpan) |
初始化 RuleSettings 类的新实例,其中除 Custom 类的值以外的所有值都是指定的。 |
RuleSettings(String, String, String, String, Int32, Int32, TimeSpan, String) |
初始化 BufferModeSettings 类的新实例,其中所有值都是指定的。 |