Greetings,
I am developing a package on my local workstation. I have defined two logging service providers. One is for SQL Server and the other is for the Windows Event Log. I am using the Dts.Log method in a script task to write log entries.
Logging is working properly with the SQL Server provider and rows are being inserted into the sysdtslog90 table. However, the only events that are being logged in the Windows Event Log are the package start and end events which I believe SSIS is doing automatically anyway.
Is there something I need to do to enable WIndows Event Log logging other than defining a log provider and making sure it is checked active? Won't SSIS write to two different logs with one Dts.Log call? Any ideas on what might be going wrong with my approach?
Thanks,
BCB
The answer is no - SSIS won't write to the Windows event log with one Dts.Log call. Writing to the event log takes a little more doing. The following code shows a method I used to do logging to the Windows event log. "rowsInserted" is a parameter that is specific to our business requirements. It can be omitted for most uses.
Public Sub WriteEventLogEntry(ByVal logMessage As String, ByVal entryType As EventLogEntryType, ByVal rowsInserted As Integer)
Try
Dim source As String
Dim log As String
Dim machine As String
' get system variables recorded in event log
Dim vars As Variables
Dts.VariableDispenser.LockOneForRead("System:ackageName", vars)
source = vars("PackageName").Value.ToString()
Dts.VariableDispenser.LockOneForRead("System::MachineName", vars)
machine = vars("MachineName").Value.ToString()
' log in Application group
log = "Application"
If Not EventLog.SourceExists(source, machine) Then
EventLog.CreateEventSource(source, log, machine)
End If
Dim eLog As New EventLog(log, machine, source)
If (rowsInserted >= 0) Then
eLog.WriteEntry(logMessage, entryType, rowsInserted)
Else
eLog.WriteEntry(logMessage, entryType) ' log does not allow negative numbers
End If
Catch ex As Exception
' do nothing - let processing continue
End Try
End Sub
No comments:
Post a Comment