Problem: I want all errors in my package to be reported to the Windows Event Log, and all other events to be logged to SQL Server.
Logging all messages to multiple locations is pretty simple. On the Configure SSIS Logs dialog (SSIS –> Logging …), you can add any number of loggers.
The tricky part of this problem is that the user wants to only log error messages to the Windows Event Log, while still receiving all of the other messages on your other log provider. The Details tab of the Configure SSIS Logs dialog lets you select individual events, but unfortunately, this applies to all loggers in the package.
There are a couple of solutions here.
Run the Package Programmatically
By running the package using the SSIS object model, you can capture all events through the IDTSEvents interface. This gives you complete control over what to do with the log messages, and which events you want to intercept. DTLoggedExec is a great example of what can be done with this approach.
Use a Script Task
In this approach, we’ll add an event handler to the package’s OnError event, and use a script task to write directly to the EventLog .
First, I add a new event handler, and drag on a script task. Note that because of the way SSIS event propagation works , we only need one event Handler at the Package level to capture all errors in the package.
The OnError event handler has a set of System Variables that we will access to create our event log message.
Name | Description |
System::ErrorCode | The error code included with the original error event |
System::ErrorDescription | The error description |
System::EventHandlerStartTime | The time the error event occurred (or close enough for logging purposes) |
System::SourceID | The GUID of the task that raised the event |
System::SourceName | The name of the task that raised the event |
System::UserName | The name of the user account that invoked the SSIS package |
System::ExecutionInstanceGUID | The GUID for this package’s execution |
System::PackageID | The GUID for the package |
System::PackageName | The name of the package |
The script task code looks like this:
public void Main()In this example the error message I’m outputting looks similar to the default one issued by the SSIS log provider for Windows Event Log, but you can customize the text to whatever format you’d like.
More information on using event handlers to do custom logging can be found here .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.