SPHealthAnalyzer.RegisterRules Method

Registers all the rules in an assembly with the SharePoint Health Analyzer rules list for the local farm.

Namespace:  Microsoft.SharePoint.Administration.Health
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Public Shared Function RegisterRules ( _
	assembly As Assembly _
) As IDictionary(Of Type, Exception)
Dim assembly As [Assembly]
Dim returnValue As IDictionary(Of Type, Exception)

returnValue = SPHealthAnalyzer.RegisterRules(assembly)


Type: System.Reflection.Assembly

An assembly that contains rules to add. SharePoint Health Analyzer rules are classes derived from the SPHealthAnalysisRule class.

Return Value

Type: System.Collections.Generic.IDictionary<Type, Exception>
A list of types that could not be registered and the exceptions that were thrown when registration failed.

The following example shows how to call the RegisterRules method in the FeatureActivated method of a class derived from the SPFeatureReceiver class. The example assumes that the feature receiver is in the same assembly as the rules that are being registered.

Public Overrides Sub FeatureActivated(ByVal properties As Microsoft.SharePoint.SPFeatureReceiverProperties)

    Dim a As Assembly = Assembly.GetExecutingAssembly()
    Dim exceptions As IDictionary(Of Type, Exception) = SPHealthAnalyzer.RegisterRules(a)

    If Not exceptions Is Nothing Then
        Dim logEntry As String = a.FullName
        If exceptions.Count = 0 Then
            logEntry += " All rules were registered."
            Dim pair As KeyValuePair(Of Type, Exception)
            For Each pair In exceptions
                logEntry += String.Format(" Registration failed for type {0}. {1}", _
                                              pair.Key, pair.Value.Message)
        End If
    End If

End Sub