How to write to task log from scheduled Functions

This should get the job done, could convert this to its own function and call it whenever is needed from another function. Should be useful as well to write out logging in cloud when debugging functions (or bpms) with no event viewer access

Action<string> writeToTaskLog = (message) => {
  foreach (var activeTask in Db.SysTask.Where(t => t.Company == Session.CompanyID && t.TaskDescription.ToLower() == "run epicor function" && t.TaskStatus.ToLower() == "active"))
  {
    var taskLog = Db.SysTaskLog.FirstOrDefault(t => t.SysTaskNum == activeTask.SysTaskNum && t.MsgText.ToLower().Contains(this.LibraryID.ToLower()));
    if (taskLog != null)
    {
      this.CallService<Ice.Contracts.SysMonitorTasksSvcContract>(sm =>{sm.WriteToTaskLog(message, taskLog.SysTaskNum, Epicor.ServiceModel.Utilities.MsgType.Info);});
    }
  }
};

I don’t think in the SysTask or SysTaskLog does it indicate the actual function running, hence why I had to find the LibraryID in the active SysTaskLog record

10 Likes