Wednesday, March 7, 2012

Problems with creating Custom Log Provider

I am new to SSIS but I am learning fast. Any help is greatly appreciated.

I have written a custom log provider derived from LogProviderBase. I want to programmtically add the custom log provider to my package, but when I try this:

myPackage.LogProviders.Add("ACustomLogProvider");

I get the following exception:

"The log provider type "ACustomLogProvider" specified for log provider "{..GUID..}" is not recognized as a valid log provider type. This error occurs when an attempt is made to create a log provider for unknown log provider type. Verify the spelling in the log provider type name".

I have followed the instructions in BOL and as suggested in this forum, adding the DtsLogProvider attribute:

[DtsLogProvider(DisplayName="ACustomLogProvider", LogProviderType="ACustomLogProvider", Description="a description")]

Another way I tried is that I added a GUID attribute to my custom log provider class and then tried this:

Type aType = typeof(ACustomLogProvider);

Guid aGUID = (Guid)aType.GUID;

myPackage.LogProviders.Add("{"+ aGUID.ToString() +"}");

This also gives me the same exception "The log provider type ""{..the actual GUID for ACustomLogProvider..}" specified for log provider "{..a different GUID..}" is not recognized as a valid log provider type....

My questions are: Is it possible to add a custom log provider programmtically or must it be done through the SSIS Designer?

Must I deploy my custom log provider class for it to work programmatically? (I had perhaps wrongly assumed I would not have to deploy if I don't want it to show up in the SSIS Designer).

I would prefer to use a custom log provider instead of just logging within the SSIS event handlers because I can override the OnPostExecute, etc. but I cannot (can I?) override the specific event handlers like PackageStart, PackageEnd, etc because they are not exposed through DTSEvents.

Any help I would be very grateful for. Thanks.

I think you need to pass fully qualified type name to Add method:

myPackage.LogProviders.Add(aType.AssemblyQualifiedName);

|||

Thank you very much, Michael. That is working great.

I appreciate your help, especially since this seems like it was a trivial question. I should have been able to see that!

Thanks,

Amy

|||

Hi,

I've trying to create a custom log provider following msdn directions from:

http://technet.microsoft.com/en-us/library/ms365184.aspx

However, the example shown there for HtmlLogProvider does not work for me. I created the dll put it in every single folder it is indicated and also used gacutil and nothing. When I go to the SQL Server Business Intelligence Development Studio and I select "Logging" from the control flow, the only available log proivders that I see are the ones that came by default with the the IDE but not the one I created (HtmlLogProvider). I would like to know if you tried it and also had the same problem and if you could give me some advice of what to do.

Thanks so much

|||Try restarting the SSIS service.|||

I finally made it work for the HtmlLog Provider but sometimes it works and sometimes it does not. By some reason sometimes it does fill data inside the html and sometimes it does nothing with it. I have wondering what may be the reason.

The steps I followed once I had the Log Provider installed in the GAC and copied into the log provider folder was to do:

Logging

Add Custom log provider

and choose the package level and som of the events (On error, etc). I also tried selecting everything.

I also tried clickng on "Log Events" but what it does is only show a window with the logged events.

Please tell me if there is a bug with the log providers in SSIS or if I am not following the right steps.

Thanks a lot

|||

I'm not aware of any bug with the log providers. The stock log providers work using the same extensibility mechanism as you should be using, so if stock log providers work OK, you need to debug why yours is not working.

It is unclear what do you mean by "sometime it does nothing with it" - have you debugged whether the log provider receives the events you expect it to receive?

|||

I am sorry I was not too specific with what I meant. Let me try to make myself more clear. First I downloaded an example of an HtmlLogProvider from MS and tried it and worked. Now I was looking at the methods that are overwritten and I wanted to create my own log provider. So I tried to do it as simple as possible. So in my dummy example I just wanted to see the errors of my dtsx pacakge thru my cutom log provider. The code is as follows:

namespace HtmlLogProviderCS

{

using System;

using Microsoft.SqlServer.Dts.Runtime;

using System.IO;

using System.Web.UI;

using System.Web;

// The LogProviderType property is required but not used.

// The custom log provider will not appear in the list

// if a LogProviderType is not provided.

[DtsLogProvider(DisplayName = "MyLogProviderTest", Description = "A simple log provider.", LogProviderType = "Custom")]

publicclassHtmlLogProviderCS : LogProviderBase

{

#region Variables and constants

// Constants.

privateconststring SUBCOMPONENT = "HtmlLogProviderCS";

privateconststring PACKAGE_END_EVENT = "PackageEnd";

// Variables.

private Microsoft.SqlServer.Dts.Runtime.Connections _connections;

private Microsoft.SqlServer.Dts.Runtime.IDTSInfoEvents _events;

privatestring _configString;

privatestring _logFile;

privateHtmlLogWriterCS _htmlLogWriter;

privateMemoryStream _logStream;

privateStreamWriter _logStreamWriter;

// Status flags.

privatebool _fireEventsAgain=true;

privatebool _loggingAlreadyStarted;

privatebool _packageHasEnded;

#endregion

publicoverridevoid InitializeLogProvider(Microsoft.SqlServer.Dts.Runtime.Connections connections, Microsoft.SqlServer.Dts.Runtime.IDTSInfoEvents events, Microsoft.SqlServer.Dts.Runtime.ObjectReferenceTracker refTracker)

{

_events = events;

System.Windows.Forms.MessageBox.Show("Init");

}

publicoverride Microsoft.SqlServer.Dts.Runtime.DTSExecResult Validate(Microsoft.SqlServer.Dts.Runtime.IDTSInfoEvents events)

{

System.Windows.Forms.MessageBox.Show("Validate");

returnDTSExecResult.Success;

}

publicoverridevoid OpenLog()

{

System.Windows.Forms.MessageBox.Show("OpenLog");

}

publicoverridevoid CloseLog()

{

System.Windows.Forms.MessageBox.Show("CloseLog");

}

publicoverridevoid Log(string logEntryName, string computerName, string operatorName, string sourceName, string sourceID, string executionID, string messageText, DateTime startTime, DateTime endTime, int dataCode, byte[] dataBytes)

{

System.Windows.Forms.MessageBox.Show("Logging...");

System.Windows.Forms.MessageBox.Show("Message is: " + logEntryName + "--" + computerName + "--" + operatorName + "--" + sourceName + "--" + sourceID + "--" + executionID + "--" + messageText);

}

}

}

Many of the variables declared in there are just there cuz they were in the example I took form the HtmlLogProvider but other than that there's no reason for them to be there. So I really do not know why this Log is not working. The weird thing is that the message that am putting for every method does pop op correctly in every method EXCEPT for the LOG method which is not even invoked.

No comments:

Post a Comment