Created
January 24, 2013 18:45
-
-
Save SimonRice/4626312 to your computer and use it in GitHub Desktop.
Log4Net + SSIS = Log4SSIS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using log4net; | |
using Microsoft.SqlServer.Dts.Runtime; | |
namespace Log4SSIS | |
{ | |
public class SSISLogProvider : LogProviderBase | |
{ | |
protected ILog _Log = LogManager.GetLogger("SSIS"); | |
public override void OpenLog() | |
{ | |
_Log.Debug("Opening logger"); | |
} | |
public override void Log(string logEntryName, string computerName, string operatorName, string sourceName, string sourceID, string executionID, string messageText, DateTime startTime, DateTime endTime, int dataCode, byte[] dataBytes) | |
{ | |
if (!string.IsNullOrEmpty(messageText)) | |
{ | |
string logMessage = string.Format("{0}: {1} ({2})", sourceName, messageText, logEntryName); | |
switch (logEntryName) | |
{ | |
case "OnPreExecute": | |
case "OnPostExecute": | |
case "OnPreValidate": | |
case "OnPostValidate": | |
_Log.Debug(logMessage); | |
break; | |
case "OnWarning": | |
_Log.Warn(logMessage); | |
break; | |
case "OnError": | |
_Log.Error(logMessage); | |
break; | |
default: | |
_Log.Info(logMessage); | |
break; | |
} | |
} | |
} | |
public override void CloseLog() | |
{ | |
_Log.Debug("Closing logger"); | |
} | |
public override DTSExecResult Validate(IDTSInfoEvents events) | |
{ | |
_Log.Debug("Validating"); | |
return DTSExecResult.Success; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.SqlServer.Dts.Runtime; | |
namespace Log4SSIS | |
{ | |
class TestProgram | |
{ | |
static void Main(string[] args) | |
{ | |
log4net.Config.XmlConfigurator.Configure(); | |
Application app = new Application(); | |
Package package = app.LoadPackage("YOUR_PACKAGE_HERE.dtsx", null); | |
package.LoggingOptions.EventFilterKind = DTSEventFilterKind.Inclusion; | |
LogProvider log = package.LogProviders.Add(typeof(SSISLogProvider).AssemblyQualifiedName); | |
package.LoggingOptions.SelectedLogProviders.Add(log); | |
package.LoggingMode = DTSLoggingMode.Enabled; | |
package.Execute(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I also want to use Log4Net for SSIS logging, could you please let me know where to keep TestProgram.cs file?