创建自定义日志提供程序Creating a Custom Log Provider

适用对象:是SQL Server,包含 Linux 版 是Azure SQL 数据库 是Azure Synapse Analytics (SQL DW) 否并行数据仓库 APPLIES TO: yesSQL Server, including on Linux yesAzure SQL Database yesAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

Integration ServicesIntegration Services 运行时环境具有广泛的日志记录功能。The Integration ServicesIntegration Services run-time environment has extensive logging capabilities. 日志可使您捕获在包执行期间发生的事件。A log lets you capture events that occur during package execution. Integration ServicesIntegration Services 包含各种日志提供程序,可用于创建日志并以诸如 XML、文本、数据库或 Windows 事件日志的格式存储这些日志。includes a variety of log providers that enable logs to be created and stored in multiple formats, such as XML, text, database, or in the Windows event log. 如果这些提供程序或输出格式不能满足您的需要,您可以创建自定义日志提供程序。If one of these providers or output formats does not fit your needs, you can create a custom log provider.

创建自定义日志提供程序的步骤与创建其他任何 Integration ServicesIntegration Services 自定义对象的步骤相似:The steps involved in creating a custom log provider are similar to the steps for creating any other custom object for Integration ServicesIntegration Services:

  • 创建一个从基类继承的新类。Create a new class that inherits from the base class. 对于日志提供程序,该基类为 LogProviderBaseFor a log provider, the base class is LogProviderBase.

  • 将标识对象类型的属性应用于该类。Apply the attribute that identifies the type of object to the class. 对于日志提供程序,该属性为 DtsLogProviderAttributeFor a log provider, the attribute is DtsLogProviderAttribute.

  • 替代基类的方法和属性的实现。Override the implementation of the base class's methods and properties. 对于日志提供程序,所涉及的属性和方法包括 ConfigString 属性以及 OpenLogLogCloseLog 方法。For a log provider, these include the ConfigString property and the OpenLog, Log, and CloseLog methods.

  • SQL ServerSQL Server Integration ServicesIntegration Services 中不实现自定义日志提供程序的自定义用户界面。Custom user interfaces for custom log providers are not implemented in SQL ServerSQL Server Integration ServicesIntegration Services.

自定义日志提供程序入门Getting Started with a Custom Log Provider

创建项目和类Creating Projects and Classes

由于所有托管日志提供程序都派生自 LogProviderBase 基类,所以创建自定义日志提供程序的第一步是以您的首选托管编程语言创建一个类库项目,然后创建一个从该基类继承的类。Because all managed log providers derive from the LogProviderBase base class, the first step when you create a custom log provider is to create a class library project in your preferred managed programming language, and then create a class that inherits from the base class. 在此派生类中重写基类的属性和方法可实现您的自定义功能。In this derived class you will override the methods and properties of the base class to implement your custom functionality.

将此项目配置为使用强名称密钥文件对将要生成的程序集进行签名。Configure the project to sign the assembly that will be generated with a strong name key file.

备注

许多 Integration ServicesIntegration Services 日志提供程序都有一个自定义用户界面,该界面实现 IDtsLogProviderUI,并用已筛选的可用连接管理器下拉列表替换“配置 SSIS 日志”对话框中的“配置”文本框 。Many Integration ServicesIntegration Services log providers have a custom user interface that implements IDtsLogProviderUI and replaces the Configuration text box in the Configure SSIS Logs dialog box with a filtered dropdown list of available connection managers. 但是,Integration ServicesIntegration Services 中不实现自定义日志提供程序的自定义用户界面。However custom user interfaces for custom log providers are not implemented in Integration ServicesIntegration Services.

应用 DtsLogProvider 属性Applying the DtsLogProvider Attribute

DtsLogProviderAttribute 属性应用于您创建的类以将其标识为日志提供程序。Apply the DtsLogProviderAttribute attribute to the class that you have created to identify it as a log provider. 此属性提供设计时信息,如日志提供程序的名称和说明。This attribute provides design-time information such as the name and description of the log provider. 此属性的 DisplayName 和 Description 属性与“配置 SSIS 日志”对话框中显示的“名称”和“说明”列相对应,该对话框在 SQL Server Data Tools (SSDT)SQL Server Data Tools (SSDT) 中为包配置日志记录时显示 。The DisplayName and Description properties of the attribute correspond to the Name and Description columns displayed in the Configure SSIS Logs editor, which is displayed when configuring logging for a package in SQL Server Data Tools (SSDT)SQL Server Data Tools (SSDT).

重要

不使用此特性的 LogProviderType 属性。The LogProviderType property of the attribute is not used. 但是,必须为该属性输入一个值,否则自定义日志提供程序将不会显示在可用日志提供程序列表中。However, you must enter a value for it, or the custom log provider will not appear in the list of available log providers.

备注

由于自定义日志提供程序的自定义用户界面不在 Integration ServicesIntegration Services 中实现,因此,为 UITypeNameDtsLogProviderAttribute 属性指定值将不起作用。Since custom user interfaces for custom log providers are not implemented in Integration ServicesIntegration Services, specifying a value for the UITypeName property of the DtsLogProviderAttribute has no effect.

<DtsLogProvider(DisplayName:="MyLogProvider", Description:="A simple log provider.", LogProviderType:="Custom")> _  
Public Class MyLogProvider  
     Inherits LogProviderBase  
    ' TODO: Override the base class methods.  
End Class  
[DtsLogProvider(DisplayName="MyLogProvider", Description="A simple log provider.", LogProviderType="Custom")]  
public class MyLogProvider : LogProviderBase  
{  
    // TODO: Override the base class methods.  
}  

生成、部署和调试自定义日志提供程序Building, Deploying, and Debugging a Custom Log Provider

Integration ServicesIntegration Services 中生成、部署和调试自定义日志提供程序的步骤与其他自定义对象类型所需的步骤非常相似。The steps for building, deploying, and debugging a custom log provider in Integration ServicesIntegration Services are very similar to the steps required for other types of custom objects. 有关详细信息,请参阅生成、部署和调试自定义对象For more information, see Building, Deploying, and Debugging Custom Objects.

另请参阅See Also

编写自定义日志提供程序代码 Coding a Custom Log Provider
为自定义日志提供程序开发用户界面Developing a User Interface for a Custom Log Provider