Skip to content

Instantly share code, notes, and snippets.

@fluxdigital
Last active June 25, 2021 00:00
Show Gist options
  • Save fluxdigital/480cfdac24212dc9cfd86e963ec69503 to your computer and use it in GitHub Desktop.
Save fluxdigital/480cfdac24212dc9cfd86e963ec69503 to your computer and use it in GitHub Desktop.
Logging to the SiteCron Last Run Log
public void Execute(IJobExecutionContext context)
{
//get details of Job
JobDataMap dataMap = context.JobDetail.JobDataMap;
string itemId = dataMap.GetString(SitecronConstants.FieldNames.ItemID);
Database masterDb = Sitecore.Configuration.Factory.GetDatabase("master");
Item jobItem = masterDb.GetItem(new ID(itemId));
try
{
//do whatever your job does here.
using (new SecurityDisabler())
{
jobItem.Editing.BeginEdit();
jobItem[SitecronConstants.FieldNames.LastRunLog] += " Last Job Execution completed successfully. ";
jobItem.Editing.EndEdit();
}
}
catch (Exception ex)
{
Log.Error($"Error with DDB CSV Import: {ex.Message} - {ex.InnerException} - {ex.StackTrace}", ex);
using (new SecurityDisabler())
{
jobItem.Editing.BeginEdit();
jobItem[SitecronConstants.FieldNames.LastRunLog] += $" Last Job Execution failed: {ex.Message} . ";
jobItem.Editing.EndEdit();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment