ConfigurationTask Scheduler

Task Scheduler

Sana Commerce 8.1
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 fileName="TaskLogFilePath"
   formatter="Text Formatter" rollSizeKB="10000"
   timeStampPattern="HH-mm-ss" rollFileExistsBehavior="Overwrite"
   header="----------------------------------------"
   footer="----------------------------------------"
   listenerDataType="Sana.Commerce.Tasks.TaskFileTraceListenerData, Sana.Commerce.Tasks.TaskScheduler"
   traceOutputOptions="None"
   type="Sana.Commerce.Tasks.TaskFileTraceListener, Sana.Commerce.Tasks.TaskScheduler"
   name="TaskFileTraceListener"/>
 
Replace the 'TaskLogFilePath' value with a fully specified path to the log file, like in example below:
fileName="d:\SanaCommerce\Logs\tasklog.txt"
'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:
fileName="d:\SanaCommerce\Logs\Task_{taskname}.txt"
then the log information for 'ProductImport' task will be written to the 'd:\SanaCommerce\Logs\Task_ProductImport.txt' 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:
fileName="d:\SanaCommerce\Logs\{taskname}\{timestamp}.txt"
every run of the 'ProductImport' task will be logged to a separate file, each having name like in the list below:
'd:\SanaCommerce\Logs\ProductImport\4-2-2010 4.38.57 PM.txt'
'd:\SanaCommerce\Logs\ProductImport\6-2-2010 4.12.33 PM.txt'
'd:\SanaCommerce\Logs\ProductImport\8-2-2010 4.25.00 PM.txt'
 
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:
fileName="d:\SanaCommerce\Logs\{taskname}\{timestamp:yyyy-MM-dd.HH-mm-ss}.txt"

For more information on date and time format strings, see the following article: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx.
 
In order to configure email trace listener, locate the following lines:
<add toAddress="ToAddress"  fromAddress="FromAddress"
   subjectLineStarter=" " subjectLineEnder=" "
   subjectFormat="{taskname} - {taskstatus}"
   statusFilter="Failed"
   smtpServer="YourSmtpServer" smtpPort="25"
   listenerDataType="Sana.Commerce.Tasks.TaskEmailTraceListenerData, Sana.Commerce.Tasks.TaskScheduler"
   traceOutputOptions="None"
   type="Sana.Commerce.Tasks.TaskEmailTraceListener, Sana.Commerce.Tasks.TaskScheduler"
   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:
statusFilter="Failed" 
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:
statusFilter="*" 
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