Actually, my colleague missed that you are using Shell
class, but the Recorder
is available only with VirtualTerminal
or TerminalControl
classes.
When using Shell
class, you have to use other kind of approach:
- use
Telnet.LogWriter
property with FileLogWriter
in Verbose
mode
- use
Telnet.LogWriter
property with modified FileLogWriter
class
- write wrapper around Shell class and log sent and received data manually
Sample usage of 1. (very verbose)
client.LogWriter = new FileLogWriter(@"path", LogLevel.Verbose);
Sample usage of 2. (logs only sent and received data in text form)
public class MyFileLogWriter : FileLogWriter
{
public MyFileLogWriter(string path) : base(path, LogLevel.Verbose) { }
public override void Write(LogLevel level, Type objectType, int objectId, string area, string message)
{
}
public override void Write(LogLevel level, Type objectType, int objectId, string area, string message, byte[] buffer, int offset, int length)
{
if ((level < Level) || (level == LogLevel.Off))
return;
WriteMessage(string.Format("{0}\r\n{1}\r\n", message, Encoding.UTF8.GetString(buffer, offset, length)));
}
}
client.LogWriter = new MyFileLogWriter(@"path");
Sample usage of 3.
public class ShellWrapper
{
Shell _inner;
public ShellWrapper(Shell shell)
{
_inner = shell;
}
private string LogReceivedData(string data)
{
Console.WriteLine("Received data:");
Console.WriteLine(data);
return data;
}
private char LogReceivedData(char data)
{
Console.WriteLine("Received data:");
Console.WriteLine(data);
return data;
}
private string LogSentData(string data)
{
Console.WriteLine("Sent data:");
Console.WriteLine(data);
return data;
}
public bool Connected { get { return _inner.Connected; } }
public Encoding Encoding { get { return _inner.Encoding; } set { _inner.Encoding = value; } }
public bool IsRunning { get { return _inner.IsRunning; } }
public string LastMatchedPrompt { get { return _inner.LastMatchedPrompt; } }
public ShellMode Mode { get { return _inner.Mode; } }
public string Prompt { get { return _inner.Prompt; } set { _inner.Prompt = value; } }
public bool StripEscapeSequences { get { return _inner.StripEscapeSequences; } set { _inner.StripEscapeSequences = value; } }
public int Timeout { get { return _inner.Timeout; } set { _inner.Timeout = value; } }
public void Close() { _inner.Close(); }
public int GetExitCode() { return _inner.GetExitCode(); }
public string ReadAll() { return LogReceivedData(_inner.ReadAll()); }
public string ReadAll(params string[] questionPrompt) { return LogReceivedData(_inner.ReadAll(questionPrompt)); }
public char ReadChar() { return LogReceivedData(_inner.ReadChar()); }
public string ReadLine() { return LogReceivedData(_inner.ReadLine()); }
public string ReadLine(params string[] questionPrompt) { return LogReceivedData(_inner.ReadLine(questionPrompt)); }
public void SendBreak(int breakLength) { LogSentData("<BREAK>"); _inner.SendBreak(breakLength); }
public void SendCommand(string command) { LogSentData(command); _inner.SendCommand(command); }
public void SendCommand(string command, bool password) { LogSentData(command); _inner.SendCommand(command, password); }
}
var shell = new ShellWrapper(client.StartShell());