Last active
June 25, 2021 00:00
-
-
Save fluxdigital/480cfdac24212dc9cfd86e963ec69503 to your computer and use it in GitHub Desktop.
Logging to the SiteCron Last Run Log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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