ConfigurationTask Scheduler

Task Scheduler

Sana Commerce 8.3
Your provider

Logging in Task Scheduler

Out of the box, the task scheduler in Sana Commerce is configured to write logging information into text files and email messages, which can be sent to a shop administrator. This functionality is implemented in two custom trace listeners, which are configured in 'web.config' file of backoffice.
In order to configure the text file trace listener, locate the following lines:
<add name="TaskFileTraceListener"
 formatter="Task Text Formatter"
 listenerDataType="Sana.Commerce.Tasks.TaskFileTraceListenerData, Sana.Commerce.Tasks"
 type="Sana.Commerce.Tasks.TaskFileTraceListener, Sana.Commerce.Tasks"/>
Replace the 'TaskLogFilePath' value with a fully specified path to the log file, like in example below:
'TaskFileTraceListener' is a reserved name for the scheduled tasks. Note, that it must be present in the task scheduler configuration section of the backoffice 'web.config' file.
Note, that there is a possibility to have separate log files per each task. In order to accomplish this you can use '{taskname}' and '{timestamp}' placeholders anywhere inside the log file path. These placeholders will be automatically replaced with, respectively, current task's name and current time stamp.
For example, if you specify the following value:
then the log information for 'ProductImport' task will be written to the 'd:\SanaCommerce\Logs\Task_ProductImport.log' file. Every time this task runs it will append the logging information to this file. Other tasks will log to another files, separate for each task.
In the following example:
every run of the 'ProductImport' task will be logged to a separate file, each having name like in the list below:
In this example, each log file name includes the time stamp of the moment when the 'ProductImport' task run started.
You can specify custom format of the time stamp by providing the date and time format string inside a '{timestamp}' placeholder as shown in the example below:

For more information on date and time format strings, see the following article:
In order to configure email trace listener, locate the following lines:
<add toAddress="ToAddress"  fromAddress="FromAddress"
   subjectLineStarter=" " subjectLineEnder=" "
   subjectFormat="{taskname} - {taskstatus}"
   smtpServer="YourSmtpServer" smtpPort="25"
   listenerDataType="Sana.Commerce.Tasks.TaskEmailTraceListenerData, Sana.Commerce.Tasks"
   type="Sana.Commerce.Tasks.TaskEmailTraceListener, Sana.Commerce.Tasks"
   name="Task Email Trace Listener"
   formatter="Email Formatter"/>
Set correct values for the following attributes:
  • toAddress - email address, which will receive all log messages from the task runner;
  • fromAddress - email address, which will be specified as a sender of the log messages;
  • smtpServer - the address of the SMTP server;
  • subjectFormat - this value will be placed in a subject of email message.
You can use the '{taskname}' and '{taskstatus}' placeholders, which will be replaced automatically with values of current task name and the status of the task run, respectively. For example, if the 'subjectFormat' is configured as follows:
subjectFormat="{taskname} - {taskstatus}"

and 'ProductImport' task has successfully finished running, then the log email will be sent with the following subject: 'ProductImport - Finished'. And in case the 'ProductImport' task has failed running, then the subject of the log email will be 'ProductImport - Failed'.

statusFilter - the log email will be sent only if status of the task run matches this value. This way it is possible to sent log emails only from tasks with a specified status.
For example, if this value is configured as follows:
then only those tasks which have finished with status 'Failed' will send log emails. The other tasks (which succeeded) will not send any log emails. If you do not want to filter log emails by task status, then set the value as follows:
Note that email trace listener sends a single email message per each separate task run. All messages logged during one task run are gathered in a 'batch', which is then written to one single email message, and the later is being sent after the task finishes running.
ConfigurationTask Scheduler