LogProviderEnumerator.Current 属性

定义

获取集合中的当前 LogProvider 元素。

public:
 property Microsoft::SqlServer::Dts::Runtime::LogProvider ^ Current { Microsoft::SqlServer::Dts::Runtime::LogProvider ^ get(); };
public Microsoft.SqlServer.Dts.Runtime.LogProvider Current { get; }
member this.Current : Microsoft.SqlServer.Dts.Runtime.LogProvider
Public ReadOnly Property Current As LogProvider

属性值

LogProvider

集合中的当前 LogProvider 元素。

示例

下面的代码示例除了使用 GetEnumerator 该方法创建枚举器外,还添加和删除包的日志提供程序,然后使用Current 该方法和 MoveNext 方法在集合上导航。

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

namespace Microsoft.SqlServer.SSIS.Samples  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            Package pkg = new Package();  
            // Make several log providers available to the package.  
            LogProvider log1 = pkg.LogProviders.Add("DTS.LogProviderEventLog.1");  
            LogProvider log2 = pkg.LogProviders.Add("DTS.LogProviderSQLProfiler.1");  
            LogProvider log3 = pkg.LogProviders.Add("DTS.LogProviderTextFile.1");  
            LogProvider log4 = pkg.LogProviders.Add("DTS.LogProviderTextFile.1");  
            // Show the log providers available to the package.  
            Console.WriteLine("Log providers available in the Package:");  
            LogProviders logs = pkg.LogProviders;  
            foreach (LogProvider lp in logs)  
                Console.WriteLine(lp.CreationName);  

            // Pick a log provider for the package.  
            pkg.LoggingOptions.SelectedLogProviders.Add(log4);  
            pkg.LoggingOptions.SelectedLogProviders.Add(log1);  
            SelectedLogProviders provs = pkg.LoggingOptions.SelectedLogProviders;  
            Console.WriteLine();  
            Console.WriteLine("Selected Log Providers for Package: {0}", provs.Count);  

            foreach (LogProvider lp in provs)  
                Console.WriteLine(lp.CreationName);  

            pkg.LoggingOptions.SelectedLogProviders.Remove(0);  
            Console.WriteLine();  
            Console.WriteLine("Count after one has been removed {0}", provs.Count);  

            // Test both the indexer and Contains method.  
            if (logs.Contains(0))  
                Console.WriteLine("Index zero in collection contains:  {0}", logs[0].CreationName);  
            else  
                throw new Exception();  

            // Show the use of the GetEnumerator.  
            LogProviderEnumerator myEnum = pkg.LogProviders.GetEnumerator();  
            Console.WriteLine("The collection contains the following values:");  
            while ((myEnum.MoveNext()) && (myEnum.Current != null))  
                Console.WriteLine("{0}", myEnum.Current.Name);  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  

Namespace Microsoft.SqlServer.SSIS.Samples  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            Dim pkg As Package =  New Package()   
            ' Make several log providers available to the package.  
            Dim log1 As LogProvider =  pkg.LogProviders.Add("DTS.LogProviderEventLog.1")   
            Dim log2 As LogProvider =  pkg.LogProviders.Add("DTS.LogProviderSQLProfiler.1")   
            Dim log3 As LogProvider =  pkg.LogProviders.Add("DTS.LogProviderTextFile.1")   
            Dim log4 As LogProvider =  pkg.LogProviders.Add("DTS.LogProviderTextFile.1")   
            ' Show the log providers available to the package.  
            Console.WriteLine("Log providers available in the Package:")  
            Dim logs As LogProviders =  pkg.LogProviders   
            Dim lp As LogProvider  
            For Each lp In logs  
                Console.WriteLine(lp.CreationName)  
            Next  

            ' Pick a log provider for the package.  
            pkg.LoggingOptions.SelectedLogProviders.Add(log4)  
            pkg.LoggingOptions.SelectedLogProviders.Add(log1)  
            Dim provs As SelectedLogProviders =  pkg.LoggingOptions.SelectedLogProviders   
            Console.WriteLine()  
            Console.WriteLine("Selected Log Providers for Package: {0}", provs.Count)  

            Dim lp As LogProvider  
            For Each lp In provs  
                Console.WriteLine(lp.CreationName)  
            Next  

            pkg.LoggingOptions.SelectedLogProviders.Remove(0)  
            Console.WriteLine()  
            Console.WriteLine("Count after one has been removed {0}", provs.Count)  

            ' Test both the indexer and Contains method.  
            If logs.Contains(0) Then  
                Console.WriteLine("Index zero in collection contains:  {0}", logs(0).CreationName)  
            Else   
                Throw New Exception()  
            End If  

            ' Show the use of the GetEnumerator.  
            Dim myEnum As LogProviderEnumerator =  pkg.LogProviders.GetEnumerator()   
            Console.WriteLine("The collection contains the following values:")  
            While (myEnum.MoveNext()) &&(myEnum.Current <> Nothing)  
                Console.WriteLine("{0}", myEnum.Current.Name)  
            End While  
        End Sub  
    End Class  
End Namespace  

示例输出:

包中提供的日志提供程序:

DTS.LogProviderTextFile.1

DTS.LogProviderSQLProfiler.1

DTS.LogProviderEventLog.1

DTS.LogProviderTextFile.1

所选的包日志提供程序:2

DTS.LogProviderTextFile.1

DTS.LogProviderEventLog.1

删除一个后计数 1

集合中的索引零包含:DTS。LogProviderTextFile.1

该集合包含以下值:

{9A4FD6D3-7DE2-43AD-8B02-CE9B02E7504B}

{AB1C156F-8018-4063-A1A5-48E122CE6FFD}

{B8E93B36-36FE-4E65-9814-9752915E9E15}

{E586A867-86EC-4901-8F5A-C945D4469C46}

注解

创建枚举器或调用 Reset 方法后,必须调用 MoveNext 方法,才能将枚举器提升到集合的第一个元素,然后枚举器才能读取 Current 属性的值:否则, 当前 未定义并引发异常。

如果返回falseMoveNext 的最后一次调用,则当前也会引发异常,这表示集合的末尾。

当前 不会移动枚举器的位置,并且对 Current 的连续调用将返回相同的对象,直到调用 MoveNextReset

只要集合保持不变,枚举器就仍有效。 如果对集合进行了更改(如添加、修改或删除元素),则枚举器将失效并变为不可恢复;因此,对 MoveNextReset 的下一次调用将引发 InvalidOperationException。 但是,如果在对 MoveNextCurrent 的调用之间修改集合, 则 Current 将返回它设置为的元素,即使枚举器已失效也是如此。

适用于