Home > SSIS, SSIS programming > Programming SSIS Logging

Programming SSIS Logging


SQL Server provides us with a powerful Data Integration service called SSIS. But to make it more robust and effective, we need to monitor some of the vital measures so as to increase its performance, troubleshooting errors and to keep track of the data flow. The best way provided by SSIS to accomplish this is SSIS Logging. SSIS will log entries in the log file or table on the basis of the events that occur during the execution of the package.

Here in this section, we will tell you about different features of SSIS logging and the implementation of the same by programming Integration Services.

Here we will consider the same package used in “SSIS Programming Basic
To start with SSIS Logging, click on “SSIS” in the menu bar or right click on empty area in Control flow and select “Logging…

ssisloggingprog1

You will get a dialog box as below. The logging is disabled by default.

ssisloggingprog2

To enable it, enable the checkbox in the Containers pane and a Provider type for the Logging. Let’s consider the Provider type is Text file i.e. “SSIS Log Provider for Text Files” and click on Add… button.

Provide a File Connection manager for Logging. Let the connection manager name is “SSIS Log.txt” (same as the file name but you can give different name for this)

ssisloggingprog3

Set the properties of the log provider as given below in the figure. Select the log provider.

ssisloggingprog4

Let’s consider that we are going to implement logging at the package level. We need information regarding “OnError” and “OnWarning” events.

List of events that are supported by SSIS are:

OnError
OnExecStatusChanged
OnInformation
OnPipelinePostEndOfRowset
OnPipelinePostPrimeOutput
OnPipelinePreEndOfRowset
OnPipelinePrePrimeOutput
OnPipelineRowsSent
OnPostExecute
OnPostValidate
OnPreExecute
OnPreValidate
OnProgress
OnQueryCancel
OnTaskFailed
OnVariableValueChanged
OnWarning
Diagnostic

[Note: The description for each of the events is given in "Configure SSIS Logs" dialog box.]

Click on Details tab to select the events that we need to track. And then click on Advanced >> button to get more options for a particular event.

Below is the list of additional information that we can log for a particular event:

Value Description
Computer The name of the computer on which the logged event occurred.
Operator The user name of the person who started the package.
SourceName The name of the package, container, or task in which the logged event occurred.
SourceID The global unique identifier (GUID) of the package, container, or task in which the logged event occurred.
ExecutionID The global unique identifier of the package execution instance.
MessageText A message associated with the log entry.
DataBytes Reserved for future use.

Let’s consider we are interested to keep Computer, SourceName and MessageText as logging information for our package as shown below.

ssisloggingprog5

Click OK, save the package and execute it.

You can see the logs generated in the file “SSIS Log.txt“.

Let’s do the same logging mechanism by SSIS programming.

Steps to follow for implementing logging mechanism in SSIS package:

Step1: Enable the logging mode of the package

package.LoggingMode = DTSLoggingMode.Enabled;

Step2: Create Log file connection manager, for our case it is a flat file named “SSIS Log.txt

Step3: Add a package log provider. In SSIS 2005 the CreationName is “DTS.LogProviderTextFile.1″

Step4: Assign connection manager to the logging provider.

Step5: Select the events that has to be considered for logging, i.e. “OnError”, OnWarning”

Step6: Select the options for each events that has to be taken for gathering information while the package is running, i.e. Computer, SourceName and MessageText. This can be achieved by using the structure DTSEventColumnFilter.

Step7: Set column filter to its respective events.

Step8: Add the rest of the components of the package.

Note: For detail about the other components of the package, please refer to our earlier post named “SSIS Programming Basic

Note: SQL Lion team had developed one application name Expert Logger to set the SSIS logging mechanism batch wise i.e. implementation of logging to any number of packages at a time. Download the free version from here.


The coding can be done in C# .net or VB .net. The code below shows the above package programmatically and the code itself is self-descriptive. The code for SQL server 2005 and SQL Server 2008 are a bit different; both the approaches are given below.

Add the below References before developing the code.

Microsoft.SqlServer.Dts.Design
Microsoft.SqlServer.DTSPipelineWrap
Microsoft.SQLServer.DTSRuntimeWrap
Microsoft.SQLServer.ManagedDTS

Programming Integration Service in SQL Server 2005

Expand image C# .Net Expand
Expand image VB .Net Expand

Programming Integration Service in SQL Server 2008

Expand image C# .Net Expand
Expand image VB .Net Expand

To make your work more easy and effortless, SQL Lion team comes up with a unique tool named “SSIS Component Explorer” that will help you in retrieving the Creation Name, Component Class ID, etc about any component like Control Flow Tasks, Data Flow Transformations, Connections Managers, Log Providers, etc in SSIS package. It also provides code snippets for each component.
Download
the free version from here.

Reference:
MSDN Books Online

Categories: SSIS, SSIS programming
  1. January 26th, 2013 at 13:43 | #1

    “Programming SSIS Logging | SQL Lion” seriously got myself
    simply addicted with ur website! I reallywill probably be back
    again far more frequently. Thanks ,Heriberto

  2. February 1st, 2013 at 12:48 | #2

    In looking for the proper collar for the pets, things that
    you need to consider are safety, the training process as well as
    your convenience. Be patient with your dog.
    Dog obedience training is a bit more than trained responses.

  1. No trackbacks yet.