IJobLogger
Describes IJobLogger in Optimizely Configured Commerce.
Code Sample
protected virtual void ProcessFiles(
SiteConnection siteConnection,
IntegrationJob integrationJob,
JobDefinitionStep jobStep,
List<string> files,
DataTable dataTableSchema,
IntegrationConnection integrationConnection,
DataSet dataSet)
{
foreach (var flatFileName in files.Distinct())
{
var dataTable = dataTableSchema.Clone();
var workingDataSet = new DataSet();
var processingFileName = string.Empty;
try
{
processingFileName = this.RenameFile(integrationJob, flatFileName);
}
catch (IOException ex)
{
this.JobLogger.Warn($"Exception {ex.Message} occurred trying to access file {processingFileName}, skipping this file");
// If the file is not available, then skip it and it will be picked up in the next run
continue;
}
this.JobLogger.Debug($"Starting Reading File {processingFileName}");
int rowCount;
try
{
rowCount = this.ParseFile(integrationJob, jobStep, processingFileName, integrationConnection, dataTable);
}
catch (Exception ex)
{
this.JobLogger.Error($"Exception Reading File {processingFileName} Moving to Bad Folder. Message: {ex.Message}");
var directoryName = Path.GetDirectoryName(processingFileName);
if (directoryName != null)
{
var badFolder = Path.Combine(directoryName, "BadFiles");
if (!Directory.Exists(badFolder))
{
Directory.CreateDirectory(badFolder);
}
File.Move(processingFileName, Path.Combine(badFolder, Path.GetFileName(processingFileName)));
}
continue;
}
// For Preview Jobs, don't archive the file
if (integrationJob.IsPreview)
{
workingDataSet.Tables.Add(dataTable);
dataSet.Merge(workingDataSet);
File.Move(processingFileName, flatFileName);
break;
}
// Only move to Processed if it is one that hasn't already been moved from a prior Step
if (!flatFileName.EndsWith(integrationJob.JobNumber + ".processed"))
{
var processedFileName = flatFileName + "." + integrationJob.JobNumber + ".processed";
File.Move(processingFileName, processedFileName);
}
this.JobLogger.Debug($"Finished Reading File {processingFileName}, Total Rows {rowCount}{(!string.IsNullOrEmpty(jobStep.WhereClause) ? " Applying Where Clause" : string.Empty)}");
if (string.IsNullOrEmpty(jobStep.WhereClause))
{
workingDataSet.Tables.Add(dataTable);
}
else
{
var filteredDataTable = dataTableSchema.Clone();
foreach (var row in dataTable.Select(jobStep.WhereClause))
{
filteredDataTable.ImportRow(row);
}
workingDataSet.Tables.Add(filteredDataTable);
this.JobLogger.Debug($"Finished Applying Where Clause, Total Rows {filteredDataTable.Rows.Count}");
}
dataSet.Merge(workingDataSet);
}
}
The example below is from an integration processor that imports flat files into a DataSet. The example logs several messages using a variety of severity levels.
Example
Severity | Comments |
---|---|
Debug | This is for debugging purposes only. These messages are not logged unless debugging is enabled. Debugging can be enabled for the integration connection or job. |
Info | This is for informational purposes. For example, you could log a message stating that a process within the integration job has completed. When executing a real-time job, these messages will not be logged unless debugging is enabled. Debugging can be enabled for the integration connection or job. |
Warn | This indicates that something probably shouldn't be happening, but the job will continue execution. For example, the FieldMap postprocessor may not find a lookup object that really should be there. Job executions can be failed if a specified number of Warn messages are logged. If this happens, the job will stop execution and not continue. |
Error | This indicates something happened that shouldn't, but the job will continue execution. For example, the FieldMap postprocessor may not find a lookup object that is required and causes an error if it cannot be found. Job executions can be failed if a specified number of Warn messages are logged. If this happens, the job will stop execution and not continue. |
Fatal | This indicates that something caused the job to fail and not continue. |
The job logs are organized by severity level or IntegrationJobLogType. There are five severity levels: Debug, Info, Warn, Error, and Fatal. Each severity level serves a different purpose and dictates different behavior in the application.
The messages that are written to the job logs appear in two places in the Admin Console. The first place is at Administration > Jobs > Job Definitions. You must then select the job definition, select the History finger tab, and select the history record. Then, select the Job Logs finger tab. The other place is at Administration > Jobs > All Job History. Find and select the correct history record. Then, select the Job Logs finger tab.
Remarks
bool ThresholdReached()
Determines if the job has reached its limit of logged warnings or errors.
ThresholdReached()
True if the message is successfully logged. False if the logging threshold is reached for either Warn or Error messages.
Returns
- jobLogType – The severity level of the log message.
- message – The log message.
Parameters
bool TryAddLogMessage(IntegrationJobLogType jobLogType, string message)
Attempts to write a log message using the specified severity level.
TryAddLogMessage(IntegrationJobLogType, string)
- message – The log message.
- jobDefinitionStep – The job step that is currently being executed.
Parameters
void Fatal(string message, JobDefinitionStep jobDefinitionStep)
Writes a formatted log message for the job step using the Fatal severity level.
Fatal(string, JobDefinitionStep)
- message – The log message.
- jobDefinitionStep – The job step that is currently being executed.
Parameters
void Error(string message, JobDefinitionStep jobDefinitionStep)
Writes a formatted log message for the job step using the Error severity level.
Error(string, JobDefinitionStep)
- message – The log message.
- jobDefinitionStep – The job step that is currently being executed.
Parameters
void Warn(string message, JobDefinitionStep jobDefinitionStep)
Writes a formatted log message for the job step using the Warn severity level.
Warn(string, JobDefinitionStep)
- message – The log message.
- jobDefinitionStep – The job step that is currently being executed.
Parameters
void Info(string message, JobDefinitionStep jobDefinitionStep)
Writes a formatted log message for the job step using the Info severity level.
Info(string, JobDefinitionStep)
- message – The log message.
- jobDefinitionStep – The job step that is currently being executed.
- logAsDebug – If true, the message will logged using the Debug severity level. Otherwise, the message will be logged using the Info severity level.
Parameters
void DebugOrInfo(string message, JobDefinitionStep jobDefinitionStep, bool logAsDebug)
Writes a formatted log message for the job step using the either the Debug or Info severity level.
DebugOrInfo(string, JobDefinitionStep, bool)
- message – The log message.
- jobDefinitionStep – The job step that is currently being executed.
Parameters
void Debug(string message, JobDefinitionStep jobDefinitionStep)
Writes a formatted log message for the job step using the Debug severity level.
Debug(string, JobDefinitionStep)
- message – The log message.
Parameters
void Fatal(string message)
Writes a log message using the Fatal severity level.
Fatal(string)
- message – The log message.
Parameters
void Error(string message)
Writes a log message using the Error severity level.
Error(string)
- message – The log message.
Parameters
void Warn(string message)
Writes a log message using the Warn severity level.
Warn(string)
- message – The log message.
Parameters
void Info(string message)
Writes a log message using the Info severity level.
Info(string)
- message – The log message.
- logAsDebug – If true, the message will logged using the Debug severity level. Otherwise, the message will be logged using the Info severity level.
Parameters
void DebugOrInfo(string message, bool logAsDebug)
Writes a log message using the either the Debug or Info severity level.
DebugOrInfo(string, bool)
- message – The log message.
Parameters
void Debug(string message)
Writes a log message using the Debug severity level.
Debug(string)
This happens when a lookup object can not be found based on the lookup field mapping specified in the job definition. Sometimes, this indicates that the field mapping is incorrectly configured or the lookup data returned from the query is empty.
Remarks
lookupErrorHandling – The specified error handling for the lookup field mapping. This is specified in the Admin Console during field mapping configuration.
- message – The log message.
Parameters
void LogMissingLookup(string message, LookupErrorHandlingType lookupErrorHandling)
Writes a log message for a missing lookup value.
LogMissingLookup(string, LookupErrorHandlingType)
Methods
A class that is capable of writing log messages during the execution of an integration job.
Updated over 1 year ago