LogProvider.GetExpression(String) 方法

定义

返回一个字符串,该字符串包含指定属性的表达式。 Null 表示未分配任何表达式。

public:
 virtual System::String ^ GetExpression(System::String ^ propertyName);
public string GetExpression (string propertyName);
abstract member GetExpression : string -> string
override this.GetExpression : string -> string
Public Function GetExpression (propertyName As String) As String

参数

propertyName
String

要查看其表达式的属性的名称。

返回

包含用于计算属性的表达式的字符串。

实现

示例

以下示例将日志提供程序的 Description 属性设置为文本“这是用于...”的日志将当前月和日追加到字符串末尾。 然后,它会验证包,该包解析表达式并将值保存到指定的 propertyName属性。 保存包时,还将对属性上的表达式设置表达式。

using System;  
using System.Collections.Generic;  
using System.Text;  
using Microsoft.SqlServer.Dts.Runtime;  

namespace LogProvider_Expression_Tests  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            // The package is one of the SSIS Samples. The package was  
            // modified to log to the SSIS log provider for Text files  
            // and saved before loading into this code.  

            string mySample = @"C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Package Samples\ExecuteProcess Sample\ExecuteProcess\UsingExecuteProcess.dtsx";  

            // Create the Application, and load the sample.  
            Application app = new Application();  
            Package pkg = app.LoadPackage(mySample, null);  

            // Get the LogProviders collection.  
            LogProviders logProvs = pkg.LogProviders;  

            // Get the "SSIS log provider for Text files"  
            // provider from the collection.  
            LogProvider textLogProv = logProvs["SSIS log provider for Text files"];  

            //Display the current description of this provider.  
            String currDescription = textLogProv.Description;  
            Console.WriteLine("Current description: {0}", currDescription);  

            // Set an expression. Only a few properties  
            // are available to have expressions. For Log Providers,   
            //current only the properties of ConfigString, Description,  
            // and Name take expressions.  
            DateTime dt = DateTime.Now;  
            String nowMonth = dt.ToString("m");  
            String newDesc = "\"This is the log for " + nowMonth + "\"";  
            textLogProv.SetExpression("Description", newDesc);  

            // Validate the package to set the expression  
            // onto the property.  
            Connections pkgConns = pkg.Connections;            
            DTSExecResult valResult = pkg.Validate(pkgConns, null, null, null);  
            if (valResult != DTSExecResult.Failure)  
            {  
                Console.WriteLine("Validation passed: {0}", valResult);  
            }  
            else  
                Console.WriteLine("Validation FAILED: {0}", valResult);  

            // Retrieve the log provider collections.  
            logProvs = pkg.LogProviders;  

            // Retreive the text log provider from the collection.  
            textLogProv = logProvs["SSIS log provider for Text files"];  

            // Check the expression, and verify that the name changed.  
            String logProvExpr = textLogProv.GetExpression("Description");  
            Console.WriteLine("The expression for Description is {0}", logProvExpr);  
            String newDescAfter = textLogProv.Description;  
            Console.WriteLine("The description is now: {0}", newDescAfter);  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  

Namespace LogProvider_Expression_Tests  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
        ' The package is one of the SSIS Samples. The package was  
        ' modified to log to the SSIS log provider for Text files  
        ' and saved before loading into this code.  
        Dim mySample As String = "C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Package Samples\ExecuteProcess Sample\ExecuteProcess\UsingExecuteProcess.dtsx"  

        ' Create the Application, and load the sample.  
        Dim app As New Application()  
        Dim pkg As Package = app.LoadPackage(mySample, Nothing)  

        ' Get the LogProviders collection.  
        Dim logProvs As LogProviders = pkg.LogProviders  

        ' Get the "SSIS log provider for Text files"  
        ' provider from the collection.  
        Dim textLogProv As LogProvider = logProvs("SSIS log provider for Text files")  

        'Display the current description of this provider.  
        Dim currDescription As String = textLogProv.Description  
        Console.WriteLine("Current description: {0}", currDescription)  

        ' Set an expression. Only a few properties  
        ' are available to have expressions. For Log Providers,   
        'current only the properties of ConfigString, Description,  
        ' and Name take expressions.  
        Dim dt As DateTime = DateTime.Now  
        Dim nowMonth As String = dt.ToString("m")  
        Dim newDesc As String = """This is the log for " + nowMonth + """"  
        textLogProv.SetExpression("Description", newDesc)  

        ' Validate the package to set the expression  
        ' onto the property.  
        Dim pkgConns As Connections = pkg.Connections  
        Dim valResult As DTSExecResult = pkg.Validate(pkgConns, Nothing, Nothing, Nothing)  
        If valResult <> DTSExecResult.Failure Then  
            Console.WriteLine("Validation passed: {0}", valResult)  
        Else  
            Console.WriteLine("Validation FAILED: {0}", valResult)  
        End If  
        ' Retrieve the log provider collections.  
        logProvs = pkg.LogProviders  

        ' Retreive the text log provider from the collection.  
        textLogProv = logProvs("SSIS log provider for Text files")  

        ' Check the expression, and verify that the name changed.  
        Dim logProvExpr As String = textLogProv.GetExpression("Description")  
        Console.WriteLine("The expression for Description is {0}", logProvExpr)  
        Dim newDescAfter As String = textLogProv.Description  
        Console.WriteLine("The description is now: {0}", newDescAfter)  
        End Sub  
    End Class  
End Namespace  

示例输出:

当前说明:将事件的日志条目写入 CSV 文件

验证已通过:成功

说明的表达式为“这是 1 月 6 日日志”

说明现在:这是 1 月 06 日日志

注解

将为 propertyName ConfigString、Description 或 Name。 对于日志提供程序,这些属性当前是唯一可以使用表达式的三个属性。

适用于