Skip to content

Logging

Robin Rodricks edited this page Feb 27, 2023 · 19 revisions

API

Modern Logger

logging diagram

Legacy Logger

  • client.LegacyLogger - A property of FtpClient. Assign this to a callback that will be fired every time a message is logged.

  • client.Config.LogToConsole - Should FTP communication be be logged to the console? Default: false.

Logging settings

  • client.Config.LogHost - Include server IP addresses in logs? Default: false.

    • Example log message if this is true: Status: Connecting to 123.123.123.123:21
    • Example log message if this is false: Status: Connecting to ***.***.***.***:21
  • client.Config.LogUserName - Include FTP usernames in logs? Default: false.

    • Example log message if this is true: Response: 331 Password required for jason_admin
    • Example log message if this is false: Response: 331 Password required for ***
  • client.Config.LogPassword - Include FTP passwords in logs? Default: false.

    • Example log message if this is true: Command: PASS supersecretST@nKS
    • Example log message if this is false: Command: PASS ***
  • client.Config.LogDurations - Include FTP command roundtrip duration in the logs? Default: true.

    • Example log message if this is true: Response: 150 File not found [5 sec]
    • Example log message if this is false: Response: 150 File not found

Which logging frameworks can I use with FluentFTP?

You can use any logging framework that creates a MELA ILogger instance, such as:

You can even use other frameworks not listed here, but then you will have to write a small wrapper function yourself.

How do I trace FTP commands for debugging?

Do this after creating your FtpClient:

client.Config.LogToConsole = true;

Alternatively:

  • You can hook onto client.LegacyLogger to get a callback every time a message is logged in the context of an individual FtpClient instance.
  • You can set any ILogger compatible logger into client.Logger

How do I log all FTP commands to a file for debugging?

You can use any logging provided to help you log to a file. You then have to set this ILogger instance provided by your logging framework into our FTP Client's Logger property.

Using Serilog

Using NLog

Using Log4Net

How do I omit sensitive information from the logs?

Use these settings to control what data is included in the logs:

  • client.Config.LogUserName - Log FTP user names?
  • client.Config.LogPassword - Log FTP passwords?
  • client.Config.LogHost - Log FTP server host/IP addresses?
Clone this wiki locally