LogProviderBase.OpenLog 方法

定义

在开始执行包时调用,以建立到外部数据源的连接。

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

示例

以下示例演示如何使用 ConnectionManager 属性中指定的 ConfigString 值连接到外部文本文件。 The connection variable was cached from the

InitializeLogProvider 方法。

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  

注解

此方法在包执行开始时调用,并在发生任何执行事件之前调用。 应使用此方法建立与外部数据源的连接,并准备响应对方法的 Log 调用。

适用于