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 類別的新執行個體,其中值是指定的。 |