SSH.NET uses the Microsoft.Extensions.Logging API to log diagnostic messages.
It is possible to specify a logger in the ConnectionInfo, for example:
using Microsoft.Extensions.Logging;
ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
{
builder.SetMinimumLevel(LogLevel.Debug);
builder.AddConsole();
});
var connectionInfo = new ConnectionInfo("sftp.foo.com",
"guest",
new PasswordAuthenticationMethod("guest", "pwd"));
connectionInfo.LoggerFactory = loggerFactory;
using (var client = new SftpClient(connectionInfo))
{
client.Connect();
}
You can also register an application-wide ILoggerFactory before using the SSH.NET APIs, this will be used as a fallback if the ConnectionInfo is not set, for example:
using Microsoft.Extensions.Logging;
ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
{
builder.SetMinimumLevel(LogLevel.Debug);
builder.AddConsole();
});
Renci.SshNet.SshNetLoggingConfiguration.InitializeLogging(loggerFactory);
All messages by SSH.NET are logged under the Renci.SshNet category.