LogProviderBase.OpenLog Metode

Definisi

Dipanggil di awal eksekusi paket untuk membuat koneksi ke sumber data eksternal.

public:
 virtual void OpenLog();
public virtual void OpenLog ();
abstract member OpenLog : unit -> unit
override this.OpenLog : unit -> unit
Public Overridable Sub OpenLog ()

Contoh

Contoh berikut menunjukkan menyambungkan ke file teks eksternal menggunakan ConnectionManager yang ditentukan dalam ConfigString properti . Variabel koneksi di-cache dari

InitializeLogProvider metode.

public override void OpenLog()  
{  
    //    Get the ConnectionManager from the package's  
    //    Connections collection.  
    connectionManager cm = connections[ConfigString];  
    //    AcquireConnection for a file ConnectionManager  
    //    retrieves the path to the file.  
    string path = (string)cm.AcquireConnection(null);  
    //    Instantiate the stream writer, and writes the opening  
    //    log entry.  
    this.sw = new StreamWriter(path);  
    sw.WriteLine("OpenLog: " + DateTime.Now.ToShortDateString());  
}  
Public Overrides  Sub OpenLog()  
    '    Get the ConnectionManager from the package's  
    '    Connections collection.  
    Dim cm As connectionManager =  connections(ConfigString)   
    '    AcquireConnection for a file ConnectionManager  
    '    retrieves the path to the file.  
    Dim path As String = CType(cm.AcquireConnection(Nothing), String)  
    '    Instantiate the stream writer, and writes the opening  
    '    log entry.  
    Me.sw = New StreamWriter(path)  
    sw.WriteLine("OpenLog: " + DateTime.Now.ToShortDateString())  
End Sub  

Keterangan

Metode ini dipanggil pada awal eksekusi paket dan sebelum peristiwa eksekusi apa pun terjadi. Anda harus menggunakan metode ini untuk membuat koneksi ke sumber data eksternal dan bersiap untuk merespons panggilan ke Log metode .

Berlaku untuk