Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

LogProviderEnumerator.Current Property

Gets the current LogProvider element in the collection.

Namespace:  Microsoft.SqlServer.Dts.Runtime
Assembly:  Microsoft.SqlServer.ManagedDTS (in Microsoft.SqlServer.ManagedDTS.dll)

public LogProvider Current { get; }

Property Value

Type: Microsoft.SqlServer.Dts.Runtime.LogProvider
The current LogProvider element in the collection.

After an enumerator is created, or after a call to the Reset method, the MoveNext method must be called to advance the enumerator to the first element of the collection before the enumerator can read the value of the Current property; otherwise, Current is undefined and throws an exception.

Current also throws an exception if the last call to MoveNext returned false, which indicates the end of the collection.

Current does not move the position of the enumerator, and consecutive calls to Current return the same object until either MoveNext or Reset is called.

An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is invalidated and becomes irrecoverable; thus, the next call to MoveNext or Reset throws an InvalidOperationException. However, if the collection is modified between calls to MoveNext and Current, Current returns the element that it is set to, even if the enumerator has been invalidated.

The following code example adds and removes log providers for the package, in addition to creating an enumerator by using the GetEnumerator method, and then uses the.Current and MoveNext methods to navigate over the collection.

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)

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

            foreach (LogProvider lp in provs)

            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);
                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);

Sample Output:

Log providers available in the Package:





Selected Log Providers for Package: 2



Count after one has been removed 1

Index zero in collection contains: DTS.LogProviderTextFile.1

The collection contains the following values:





Community Additions

© 2015 Microsoft