开发者

Using log4net as a logging mechanism for SSIS?

开发者 https://www.devze.com 2022-12-28 20:04 出处:网络
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?

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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消