Enabling SShNet.Logging

Jan 15, 2016 at 5:05 PM
I have seen several example of people post logging from SshNet.Logging and was wondering how to turn this on. We need to roubleshoot a problem with one of our command line utilities built with sshnet.
Apr 25, 2016 at 5:18 PM
You have to use a debug build of Renci.SshNet.dll, and you need to configure a listener for the "SshNet.Logging" TraceSource in your application's config file (e.g., SftpTest.exe.config if you're running in SftpTest.exe). Here's an example that sends the trace output to the console:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.diagnostics>
        <sources>
            <source name="SshNet.Logging">
                <listeners>
                    <add name="Console" type="System.Diagnostics.ConsoleTraceListener"/>
                </listeners>
            </source>
        </sources>
    </system.diagnostics>
</configuration>
Note: SSH.NET only logs in debug builds because the "void Log(string text)" method in Session.NET.cs is marked with the [Conditional("DEBUG")] attribute. So in release builds the compiler eliminates all calls to the Log method, which means configuring a trace source listener for "SshNet.Logging" will do no good for release builds.

HTH,

Bill