Class StructuredLoggingJobHistoryPlugin
Logs a history of all job executions (and execution vetoes) via structured logging.
[SuppressMessage("Performance", "CA1848:Use the LoggerMessage delegates", Justification = "The template is the user's, configured at run time, and its named placeholders are what a structured sink resolves into properties - which is the whole reason this plugin exists. A [LoggerMessage] template is fixed at compile time, and rendering this one first would flatten exactly what is being preserved. Every call is already behind an IsEnabled check, so the allocation CA1848 exists to avoid is already avoided. LogCallSiteTest.Allowed records the same decision from the source side.")]
public sealed class StructuredLoggingJobHistoryPlugin : ISchedulerPlugin, IJobListener
- Inheritance
-
StructuredLoggingJobHistoryPlugin
- Implements
- Inherited Members
Remarks
This is a structured logging alternative to LoggingJobHistoryPlugin.
Unlike LoggingJobHistoryPlugin, message templates use named parameters
(e.g. {JobName}, {TriggerGroup}) 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
StructuredLoggingJobHistoryPlugin()
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 StructuredLoggingJobHistoryPlugin()
StructuredLoggingJobHistoryPlugin(ILogger<StructuredLoggingJobHistoryPlugin>, TimeProvider)
Creates the plugin with the logger and clock a container resolved, which is what
UseStructuredJobLogging uses.
public StructuredLoggingJobHistoryPlugin(ILogger<StructuredLoggingJobHistoryPlugin> logger, TimeProvider timeProvider)
Parameters
loggerILogger<StructuredLoggingJobHistoryPlugin>Where the history events go.
timeProviderTimeProviderThe clock the events are stamped with.
Properties
JobFailedMessage
Gets or sets the message that is logged when a Job fails its execution.
public string JobFailedMessage { get; }
Property Value
JobSuccessMessage
Gets or sets the message that is logged when a Job successfully completes its execution.
public string JobSuccessMessage { get; }
Property Value
JobToBeFiredMessage
Gets or sets the message that is logged when a Job is about to be executed.
public string JobToBeFiredMessage { get; }
Property Value
JobWasVetoedMessage
Gets or sets the message that is logged when a Job execution is vetoed by a trigger listener.
public string JobWasVetoedMessage { get; }
Property Value
Name
Get the name of the IJobListener.
public string Name { get; }
Property Value
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
pluginNamestringschedulerISchedulercancellationTokenCancellationToken
Returns
JobExecutionVetoed(IJobExecutionContext, CancellationToken)
Called by the IScheduler when a IJobDetail was about to be executed (an associated ITrigger has occurred), but a ITriggerListener vetoed it's execution.
public ValueTask JobExecutionVetoed(IJobExecutionContext context, CancellationToken cancellationToken = default)
Parameters
contextIJobExecutionContextcancellationTokenCancellationToken
Returns
- See Also
JobToBeExecuted(IJobExecutionContext, CancellationToken)
Called by the IScheduler when a IJobDetail is about to be executed (an associated ITrigger has occurred).
This method will not be invoked if the execution of the Job was vetoed by a ITriggerListener.
public ValueTask JobToBeExecuted(IJobExecutionContext context, CancellationToken cancellationToken = default)
Parameters
contextIJobExecutionContextcancellationTokenCancellationToken
Returns
- See Also
JobWasExecuted(IJobExecutionContext, JobExecutionException?, CancellationToken)
Called by the IScheduler after a IJobDetail has been executed, and before the associated ITrigger's Triggered(ICalendar?) method has been called.
public ValueTask JobWasExecuted(IJobExecutionContext context, JobExecutionException? jobException, CancellationToken cancellationToken = default)
Parameters
contextIJobExecutionContextjobExceptionJobExecutionExceptioncancellationTokenCancellationToken