Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using log4net as a logging mechanism for SSIS?

Tags:

log4net

ssis

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.

like image 793
enriquein Avatar asked Apr 29 '10 14:04

enriquein


People also ask

How do I enable event logging in SSIS?

Select Provider type: SSIS log provider for Windows Event Log and click Add. Now Execute the package . After package is executed, go to Control Panel – > Administrative Tools – > Event Viewer – >Windows Logs – > click on Application – > under Source tab with value “SQLISService” are package logged information.

What is the use of log4net DLL?

The Apache log4net library is a tool to help the programmer output log statements to a variety of output targets. log4net is a port of the excellent Apache log4j™ framework to the Microsoft® . NET runtime.


1 Answers

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.

like image 91
enriquein Avatar answered Oct 02 '22 17:10

enriquein