Skip to content

Instantly share code, notes, and snippets.

@jraps20
Last active Jul 3, 2018
Embed
What would you like to do?
using Quartz;
using Sitecron.SitecronSettings;
public abstract class SiteCronBase : IJob
{
private DateTime _lastLogEntry;
protected abstract void Run(IJobExecutionContext args);
public void Execute(IJobExecutionContext context)
{
var startExecution = DateTime.Now;
_lastLogEntry = DateTime.Now;
Run(context);
_lastLogEntry = startExecution;
WriteLogLine(context, "Job completed in elapsed time shown.");
}
protected void WriteLogLine(IJobExecutionContext context, string value)
{
var log = context.JobDetail.JobDataMap.GetString(SitecronConstants.ParamNames.SitecronJobLogData);
var line = $"{DateTime.Now.ToUniversalTime()} - - {value}, Elapsed time since last step: {(DateTime.Now - _lastLogEntry).TotalSeconds} seconds";
Log.Info(line, this);
log = log + "\r\n" + line;
context.JobDetail.JobDataMap.Put(SitecronConstants.ParamNames.SitecronJobLogData, log);
_lastLogEntry = DateTime.Now;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment