Export (0) Print
Expand All
2 out of 2 rated this helpful - Rate this topic

Logging in the Script Task

The use of logging in Integration Services packages lets you record detailed information about execution progress, results, and problems by recording predefined events or user-defined messages for later analysis. The Script task can use the Log method of the Dts object to log user-defined data. If logging is enabled, and the ScriptTaskLogEntry event is selected for logging on the Details tab of the Configure SSIS Logs dialog box, a single call to the Log method stores the event information in all the log providers configured for the task.

Note Note

Although you can perform logging directly from your Script task, you may want to consider implementing events rather than logging. When using events, not only can you enable the logging of event messages, but you can also respond to the event with default or user-defined event handlers.

For more information about logging, see Integration Services (SSIS) Logging.

The following example demonstrates logging from the Script task by logging a value that represents the number of rows processed.

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;

public class ScriptMain
{


    public void Main()
        {
            //
            int rowsProcessed = 100;
            byte[] emptyBytes = new byte[0];

            try
            {
                Dts.Log("Rows processed: " + rowsProcessed.ToString(), 0, emptyBytes);
                Dts.TaskResult = (int)ScriptResults.Success;
            }
            catch (Exception ex)
            {
                //An error occurred.
                Dts.Events.FireError(0, "Script Task Example", ex.Message + "\r" + ex.StackTrace, String.Empty, 0);
                Dts.TaskResult = (int)ScriptResults.Failure;
            }

        }

}

Integration Services icon (small)  Stay Up to Date with Integration Services

For the latest downloads, articles, samples, and videos from Microsoft, as well as selected solutions from the community, visit the Integration Services page on MSDN:


For automatic notification of these updates, subscribe to the RSS feeds available on the page.

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.