The EmailLogProvider sample demonstrates how to create a custom log provider, the Email Log Provider, which sends logging output as an e-mail message in either plain text or HTML format. This sample is not supported on Itanium-based operating systems.
For more information about how to create a custom log provider, see Creating a Custom Log Provider. For general information about the use of log providers in Integration Services, see Integration Services Log Providers.
The custom log provider expects a semicolon-delimited list of strings that specify the SMTP server, the To address, the From address, and whether the message is in text or HTML format. The log provider caches logged events, and when the package finishes running, it sends the cached output in the body of a mail message. It ignores the final two standard columns (dataCode and dataBytes) which may contain binary data that cannot be displayed correctly. The sample encapsulates the text logging code in a separate TextLogWriter class, and the HTML logging code in a separate HtmlLogWriter class, for ease of reuse. Each of these helper classes has OpenLog<format>, Log<format>, and CloseLog<format> subroutines, which are called from OpenLog, Log, and CloseLog respectively.
This code sample implements the following functionality:
Overriding of the LogProviderBase class.
Default persistence support that does not require the developer to write custom persistence code.
|Samples are provided for educational purposes only. They are not intended to be used in a production environment and have not been tested in a production environment. Microsoft does not provide technical support for these samples.|
If you already know how to locate, build, and install code samples, you can go directly to the section Testing the Sample, and read about how to configure and run the code sample.
If the code sample was installed to the default location, the sample is located in the following directory:
C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\\Programming Samples\Control Flow\EmailLogProvider Sample
The C# solution for the code sample is located in the CS directory, and the Visual Basic solution is located in the VB directory.
For information about the two-step process required to install the samples, see Installing Samples. To obtain the latest version of the samples, including new samples released after the original release of SQL Server 2005, see SQL Server 2005 Samples and Sample Databases (April 2006).
If you have not already generated a strong name key file in the Samples folder, use the following procedure to generate this key file. The sample projects are configured on the Signing tab of the Project Properties dialog box to sign assemblies at build time with this key file.
To open a Microsoft Visual Studio 2005 command prompt, click Start, point to All Programs, point to Microsoft Visual Studio 2005, point to Visual Studio Tools, and then click Visual Studio 2005 Command Prompt.
- or -
To open a Microsoft .NET Framework command prompt, click Start, point to All Programs, point to Microsoft .NET Framework SDK v2.0, and then click SDK Command Prompt.
At the command prompt, use the change directory (CD) command to change the current folder of the command prompt to the Samples folder. The key file that you create in this folder will be used by all SQL Server 2005 code samples.
Note: To determine the folder where samples are located, click Start, point to All Programs, point to Microsoft SQL Server 2005, point to Documentation and Tutorials, and then click Samples Directory. If the default installation location was used, the samples are located in <system_drive>:\Program Files\Microsoft SQL Server\90\Samples.
At the command prompt, run the following command to generate the key file:
sn -k SampleKey.snk
Important: For more information about the strong-name key pair, see "Security Briefs: Strong Names and Security in the .NET Framework" in the .NET Development Center on MSDN.
This sample is provided in both Visual Basic and C#. To distinguish the assemblies for each version of the sample, the name of the output assembly has CS or VB appended. After successfully building the component, follow these steps in order to add it as a connection manager in a package in Business Intelligence Development Studio.
Open a Command Prompt window.
Type the following commands to install the C# version of the component into the GAC:
gacutil.exe -iF " C:\Program Files\Microsoft SQL Server\90\Samples\Integration Services\Programming Samples\Control Flow\EmailLogProvider Sample\CS\EmailLogProviderCS\bin\Debug\EmailLogProviderCS.dll"
- or -
Type the following commands to install the Visual Basic version of the component into the GAC:
gacutil.exe -iF " C:\Program Files\Microsoft SQL Server\90\Samples\Integration Services\Programming Samples\Control Flow\EmailLogProvider Sample\VB\EmailLogProviderVB\bin\Debug\EmailLogProviderVB.dll"
You can now test the custom log provider in a package.
Confirm the name of an available SMTP server.
From the SSIS menu, select Logging, and add the Custom log provider for mail messages (CS) or Custom log provider for mail messages (VB). You may want to configure two instances of the log provider so that you can test both the text and the HTML output formats.
In the Configuration column, enter a semicolon-delimited list of four strings that specify the SMTP server, the To address, the From address, and whether the message is in text or HTML format. For example:
Configure logging as appropriate so that the package and its components log their events to the custom log provider.
Run the package, and then view the mail messages that contain the logging output in your mail program.