views:

172

answers:

2

Does anyone know if it is possible to do logging in SSIS (SQL Server Integration Services) via log4net? If so, any pointers and pitfalls to be aware of? How's the deployment story?

I know the best solution to my problem is to not use SSIS. The reality is that as much as I hate this POS technology, the company I work with encourages the use of these apps instead of writing code. Meh.

A: 

So to answer my own question: it is possible. I'm not sure how our deployment story will be since this will be done in a few weeks from now.

I pretty much took the information from these sources and made it work. This one explains how to make referencing assemblies work with SSIS, click here. TLDR version: place it in the GAC and also copy the dll to the folder of your targetted framework. In my case, C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727. To programmatically configure log4net I ended up using this link as reference.

This is how my logger configuration code looks like for creating a file with the timestamp on it:

using log4net;
using log4net.Config;
using log4net.Layout;
using log4net.Appender;

public class whatever
{
    private ILog logger; 
    public void InitLogger()
    {
        PatternLayout layout = new PatternLayout("%date [%level] - %message%newline");
        FileAppender fileAppenderTrace = new FileAppender();
        fileAppenderTrace.Layout = layout;
        fileAppenderTrace.AppendToFile = false;

        // Insert current date and time to file name
        String dateTimeStr = DateTime.Now.ToString("yyyyddMM_hhmm");
        fileAppenderTrace.File = string.Format("c:\\{0}{1}", dateTimeStr.Trim() ,".log");

        // Configure filter to accept log messages of any level.
        log4net.Filter.LevelMatchFilter traceFilter = new log4net.Filter.LevelMatchFilter();
        traceFilter.LevelToMatch = log4net.Core.Level.All;
        fileAppenderTrace.ClearFilters();
        fileAppenderTrace.AddFilter(traceFilter);

        fileAppenderTrace.ImmediateFlush = true;
        fileAppenderTrace.ActivateOptions();

        // Attach appender into hierarchy
        log4net.Repository.Hierarchy.Logger root = ((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root;
        root.AddAppender(fileAppenderTrace);
        root.Repository.Configured = true;
        logger = log4net.LogManager.GetLogger("root");
    }
}

Hopefully this might help someone in the future or at least serve as a reference if I ever need to do this again.

enriquein
A: 

Sorry, you didn't dig deep enough. There are 5 different destinations that you can log to, and 7 columns you can choose to include or not include in your logging as well as between 18 to 50 different events that you can capture logging on. You appear to have chosen the default logging, and dismissed it because it didn't work for you out of the box.
Check these two blogs for more information on what can be done with SSIS logging: http://consultingblogs.emc.com/jamiethomson/archive/2005/06/11/SSIS_3A00_-Custom-Logging-Using-Event-Handlers.aspx
http://www.sqlservercentral.com/blogs/michael_coles/archive/2007/10/09/3012.aspx

William Todd Salzman
Before I posted my answer I had already tried the built in logging mechanism and played around with the customization. What I didn't think about was using the event handlers to enrich that functionality. The link to Jamie's blog was a pretty interesting read. I think I'm going to give that a shot as well to be fair. That still doesn't fix the problem with logfiles growing out of control, though. Nor does it fix the ability to dinamycally change the verbosity of logging. Still, I feel SSIS logging could be useful for logging to anything other than files. Thanks again for the suggestion.
enriquein