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 static IDictionary<Type, Exception> RegisterRules(
	Assembly 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 override void FeatureActivated(SPFeatureReceiverProperties properties)
    Assembly a = Assembly.GetExecutingAssembly();
    IDictionary<Type, Exception> exceptions = SPHealthAnalyzer.RegisterRules(a);

    if (exceptions != null)
        string logEntry = a.FullName;
        if (exceptions.Count == 0)
            logEntry += " All rules were registered.";
            foreach (KeyValuePair<Type, Exception> pair in exceptions)
                logEntry += string.Format(" Registration failed for type {0}. {1}",
                                          pair.Key, pair.Value.Message);