Analyzers provide a mechansim to run validation checks, inspect documents, and otherwise report on the status of your content and data.
An analyzer implements
IAnalyzer and is run on the output documents from one (or more) pipeline(s) and phase(s). Analyzers are run after each phase so exceptions propogate immediatly, but analyzer results are reported at the end of execution. An analyzer receives an
IAnalyzerContext that includes the documents to be analyzed as
AddAnalyzerResult(...) method used to add analyzer messages.
Some base classes are provided that make writing analyzers easier:
Analyzeris a basic analyzer that analyzes documents from one (or more) pipeline(s) and phase(s).
SyncAnalyzercan be used when the analyze method should be synchronous (I.e. not
An analyzer defines which pipeline(s) and phase(s) it should be run after using the
PipelinePhases property. Analyzers also define a default logging level their result messages should be logged as using the
LogLevel property (which can be overriden, see below).
Using The Bootstrapper
The Bootstrapper also includes some extension methods like
AnalyzeDocument(...) that let you define analyzers as a delegate.
Registering With The Bootstrapper
When using the Bootstrapper all analyzer classes in the entry assembly are instantiated and added with their default log level automatically.
The Bootstrapper also has a number of
AddAnalyzer(...) methods that allow you to manually register analyzers and optionally define their log level.
Registering In Settings And Metadata
Analyzers: - ValidateSomeMetadata
This will add the
ValidateSomeMetadata analyzer (provided it exists within referenced assemblies). The analyzer will be added with it's default log level, but you can also specify a different log level by using an equal sign:
Analyzers: - ValidateSomeMetadata=Warning
This will register the
ValidateSomeMetadata analyzer with a log level of
Warning, or change the log level to
Warning if the analyzer has previously been registered.
You can also change the log level of a registered analyzer on a per-document basis using metadata. For example, to disable the
ValidateSomeMetadata analyzer for a prtocular document, place the following in the front matter of the document:
Analyzers: - ValidateSomeMetadata=None
Registering On The Command Line
Analyzers can be registered and log levels set using the command line as well using either
--analyzer and the same
name=log-level syntax. For example:
dotnet run -- -a ValidateSomeMetadata=Warning