다음을 통해 공유


LogProvider.SetExpression(String, String) 메서드

정의

지정한 식을 속성에 할당합니다. 속성에서 기존 식을 제거하려면 null을 지정합니다.

public:
 virtual void SetExpression(System::String ^ propertyName, System::String ^ expression);
public void SetExpression (string propertyName, string expression);
abstract member SetExpression : string * string -> unit
override this.SetExpression : string * string -> unit
Public Sub SetExpression (propertyName As String, expression As String)

매개 변수

propertyName
String

식을 할당할 속성의 이름입니다.

expression
String

식입니다.

구현

예제

다음 예제에서는 로그 공급자의 Description 속성을 텍스트로 설정합니다. 문자열의 끝에 현재 월과 요일이 추가된 경우

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월 06일 로그입니다."입니다.

설명은 이제 다음과 같습니다. 1월 06일에 대한 로그입니다.

설명

propertyName ConfigString, 설명 또는 이름이 됩니다. 로그 공급자의 경우 현재 식을 사용할 수 있는 세 가지 속성만 있습니다.

적용 대상