PowerTCP Telnet for .NET CF
Log Event
See Also  Example Send comments on this topic.
Dart.Common Namespace > TcpBase Class : Log Event




Used to capture protocol data.

Syntax

Visual Basic (Declaration) 
Public Event Log As LogEventHandler
Visual Basic (Usage)Copy Code
Dim instance As TcpBase
Dim handler As LogEventHandler
 
AddHandler instance.Log, handler
C# 
public event LogEventHandler Log
Managed Extensions for C++ 
public: __event LogEventHandler* Log
C++/CLI 
public:
event LogEventHandler^ Log

Example

This example demonstrates logging sent and received data to a file on disk.
C#Copy Code
logFile = 
	new FileStream(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + 
        "\\logFile.txt", FileMode.Append, FileAccess.Write);
}

private void myComponent_Log(object sender, LogEventArgs e)
{
    string prompt = (e.Data.Direction == DataDirection.In) ? "Recv: " : "Sent: ";
    logFile.Write(System.Text.Encoding.Default.GetBytes(prompt), 0,prompt.Length);
    logFile.Write(e.Data.Buffer, e.Data.Offset, e.Data.Count);
    logFile.Write(System.Text.Encoding.Default.GetBytes("\r\n"), 0, 2);
}
Visual BasicCopy Code
Dim logFile As New FileStream(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + _
    "\logFile.txt", FileMode.Append, FileAccess.Write)

Private Sub myComponent_Log(ByVal sender As Object, ByVal e As LoggingEventArgs) Handles myComponent.Log
    Dim prompt As String = ""
    If e.DataDirection = DataDirection.In) Then
        prompt = "Recv: "
    Else
        prompt = "Sent: "
    End If
    logFile.Write(System.Text.Encoding.Default.GetBytes(prompt), 0, prompt.Length)
    logFile.Write(e.Data.Buffer, e.Data.Offset, e.Data.Count)
    logFile.Write(System.Text.Encoding.Default.GetBytes(vbCrLf), 0, 2)
End Sub

Remarks

The handler must be added before connecting. Set EnableLogEvent to turn logging on and off.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 4.2
© 2010 Dart Communications. All Rights Reserved.