Table of Contents

Class StructuredLoggingTriggerHistoryPlugin

Namespace
Quartz.Plugins.History
Assembly
Quartz.Plugins.dll

Logs a history of all trigger firings via structured logging.

[SuppressMessage("Performance", "CA1848:Use the LoggerMessage delegates", Justification = "Same as StructuredLoggingJobHistoryPlugin: the configured template's named placeholders are the plugin's reason to exist, and they cannot survive a compile-time template. Every call is already behind an IsEnabled check. LogCallSiteTest.Allowed records the same decision from the source side.")]
public sealed class StructuredLoggingTriggerHistoryPlugin : ISchedulerPlugin, ITriggerListener
Inheritance
StructuredLoggingTriggerHistoryPlugin
Implements
Inherited Members

Remarks

This is a structured logging alternative to LoggingTriggerHistoryPlugin. Unlike LoggingTriggerHistoryPlugin, message templates use named parameters (e.g. {TriggerName}, {JobGroup}) instead of index-based placeholders. This makes log output compatible with structured logging sinks like Serilog and NLog, and avoids template cache memory leaks.

Message templates can be customized via properties. The parameter names in the templates must match the default names exactly (they are positionally mapped).

Constructors

StructuredLoggingTriggerHistoryPlugin()

Creates the plugin with the static logger and the system clock, for a plugin the loader built from a quartz.plugin.<name>.type key and so had nothing to inject into.

public StructuredLoggingTriggerHistoryPlugin()

StructuredLoggingTriggerHistoryPlugin(ILogger<StructuredLoggingTriggerHistoryPlugin>, TimeProvider)

Creates the plugin with the logger and clock a container resolved, which is what UseStructuredTriggerLogging uses.

public StructuredLoggingTriggerHistoryPlugin(ILogger<StructuredLoggingTriggerHistoryPlugin> logger, TimeProvider timeProvider)

Parameters

logger ILogger<StructuredLoggingTriggerHistoryPlugin>

Where the history events go.

timeProvider TimeProvider

The clock the events are stamped with.

Properties

Name

Get the name of the ITriggerListener.

public string Name { get; }

Property Value

string

TriggerCompleteMessage

Gets or sets the message that is logged when a trigger completes.

public string TriggerCompleteMessage { get; }

Property Value

string

TriggerFiredMessage

Gets or sets the message that is logged when a trigger fires.

public string TriggerFiredMessage { get; }

Property Value

string

TriggerMisfiredMessage

Gets or sets the message that is logged when a trigger misfires.

public string TriggerMisfiredMessage { get; }

Property Value

string

Methods

Initialize(string, IScheduler, CancellationToken)

Called during creation of the IScheduler in order to give the ISchedulerPlugin a chance to Initialize.

public ValueTask Initialize(string pluginName, IScheduler scheduler, CancellationToken cancellationToken = default)

Parameters

pluginName string
scheduler IScheduler
cancellationToken CancellationToken

Returns

ValueTask

TriggerComplete(ITrigger, IJobExecutionContext, SchedulerInstruction, CancellationToken)

Called by the IScheduler when a ITrigger has fired, it's associated IJobDetail has been executed, and it's Triggered(ICalendar?) method has been called.

public ValueTask TriggerComplete(ITrigger trigger, IJobExecutionContext context, SchedulerInstruction triggerInstructionCode, CancellationToken cancellationToken = default)

Parameters

trigger ITrigger

The ITrigger that was fired.

context IJobExecutionContext

The IJobExecutionContext that was passed to the IJob'sExecute(IJobExecutionContext, CancellationToken) method.

triggerInstructionCode SchedulerInstruction

The result of the call on the ITrigger'sTriggered(ICalendar?) method.

cancellationToken CancellationToken

The cancellation instruction.

Returns

ValueTask

Remarks

The default implementation does nothing.

TriggerFired(ITrigger, IJobExecutionContext, CancellationToken)

Called by the IScheduler when a ITrigger has fired, and it's associated IJobDetail is about to be executed.

It is called before the VetoJobExecution(ITrigger, IJobExecutionContext, CancellationToken) method of this interface.

public ValueTask TriggerFired(ITrigger trigger, IJobExecutionContext context, CancellationToken cancellationToken = default)

Parameters

trigger ITrigger

The ITrigger that has fired.

context IJobExecutionContext

The IJobExecutionContext that will be passed to the IJob'sExecute(IJobExecutionContext, CancellationToken) method.

cancellationToken CancellationToken

The cancellation instruction.

Returns

ValueTask

Remarks

The default implementation does nothing.

TriggerMisfired(ITrigger, IScheduler, CancellationToken)

Called by the IScheduler when a ITrigger has misfired.

Consideration should be given to how much time is spent in this method, as it will affect all triggers that are misfiring. If you have lots of triggers misfiring at once, it could be an issue it this method does a lot.

public ValueTask TriggerMisfired(ITrigger trigger, IScheduler scheduler, CancellationToken cancellationToken = default)

Parameters

trigger ITrigger

The ITrigger that has misfired.

scheduler IScheduler

The scheduler raising the notification.

cancellationToken CancellationToken

The cancellation instruction.

Returns

ValueTask

Remarks

The scheduler is passed because a misfire is noticed outside any execution, so there is no IJobExecutionContext here to reach it through. It comes after the trigger, as the context does on every other notification in this interface.

The default implementation does nothing.

VetoJobExecution(ITrigger, IJobExecutionContext, CancellationToken)

Called by the IScheduler when a ITrigger has fired, and it's associated IJobDetail is about to be executed.

It is called after the TriggerFired(ITrigger, IJobExecutionContext, CancellationToken) method of this interface. If the implementation vetoes the execution (via returning true), the job's execute method will not be called.

public ValueTask<bool> VetoJobExecution(ITrigger trigger, IJobExecutionContext context, CancellationToken cancellationToken = default)

Parameters

trigger ITrigger

The ITrigger that has fired.

context IJobExecutionContext

The IJobExecutionContext that will be passed to the IJob'sExecute(IJobExecutionContext, CancellationToken) method.

cancellationToken CancellationToken

The cancellation instruction.

Returns

ValueTask<bool>

Returns true if job execution should be vetoed, false otherwise.

Remarks

The default implementation vetoes nothing.