Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

IJobLogger

Describes class that is capable of writing log messages during the execution of an integration job.

Description

A class that is capable of writing log messages during the execution of an integration job.

Methods

LogMissingLookup(string, LookupErrorHandlingType)

Writes a log message for a missing lookup value.

void LogMissingLookup(string message, LookupErrorHandlingType lookupErrorHandling)

Parameters

  • message – The log message.

lookupErrorHandling – The specified error handling for the lookup field mapping. This is specified in the Admin Console during field mapping configuration.

Remarks

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.

Debug(string)

Writes a log message using the Debug severity level.

void Debug(string message)

Parameters

  • message – The log message.

DebugOrInfo(string, bool)

Writes a log message using the either the Debug or Info severity level.

void DebugOrInfo(string message, bool logAsDebug)

Parameters

  • 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.

Info(string)

Writes a log message using the Info severity level.

void Info(string message)

Parameters

  • message – The log message.

Warn(string)

Writes a log message using the Warn severity level.

void Warn(string message)

Parameters

  • message – The log message.

Error(string)

Writes a log message using the Error severity level.

void Error(string message)

Parameters

  • message – The log message.

Fatal(string)

Writes a log message using the Fatal severity level.

void Fatal(string message)

Parameters

  • message – The log message.

Debug(string, JobDefinitionStep)

Writes a formatted log message for the job step using the Debug severity level.

void Debug(string message, JobDefinitionStep jobDefinitionStep)

Parameters

  • message – The log message.
  • jobDefinitionStep – The job step that is currently being executed.

DebugOrInfo(string, JobDefinitionStep, bool)

Writes a formatted log message for the job step using the either the Debug or Info severity level.

void DebugOrInfo(string message, JobDefinitionStep jobDefinitionStep, bool logAsDebug)

Parameters

  • 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.

Info(string, JobDefinitionStep)

Writes a formatted log message for the job step using the Info severity level.

void Info(string message, JobDefinitionStep jobDefinitionStep)

Parameters

  • message – The log message.
  • jobDefinitionStep – The job step that is currently being executed.

Warn(string, JobDefinitionStep)

Writes a formatted log message for the job step using the Warn severity level.

void Warn(string message, JobDefinitionStep jobDefinitionStep)

Parameters

  • message – The log message.
  • jobDefinitionStep – The job step that is currently being executed.

Error(string, JobDefinitionStep)

Writes a formatted log message for the job step using the Error severity level.

void Error(string message, JobDefinitionStep jobDefinitionStep)

Parameters

  • message – The log message.
  • jobDefinitionStep – The job step that is currently being executed.

Fatal(string, JobDefinitionStep)

Writes a formatted log message for the job step using the Fatal severity level.

void Fatal(string message, JobDefinitionStep jobDefinitionStep)

Parameters

  • message – The log message.
  • jobDefinitionStep – The job step that is currently being executed.

TryAddLogMessage(IntegrationJobLogType, string)

Attempts to write a log message using the specified severity level.

bool TryAddLogMessage(IntegrationJobLogType jobLogType, string message)

Parameters

  • jobLogType – The severity level of the log message.
  • message – The log message.

Returns

True if the message is successfully logged. False if the logging threshold is reached for either Warn or Error messages.

ThresholdReached()

Determines if the job has reached its limit of logged warnings or errors.

bool ThresholdReached()

Remarks

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.

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.

SeverityComments
DebugThis is for debugging purposes only. These messages are not logged unless debugging is enabled. Debugging can be enabled for the integration connection or job.
InfoThis 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.
WarnThis 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.
ErrorThis 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.
FatalThis indicates that something caused the job to fail and not continue.

Example

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.

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's 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);
        }
    }