Skip to content

Logging

Robin Rodricks edited this page Dec 28, 2022 · 20 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.

  • client.Config.LogUserName - Include FTP usernames in logs? Default: false.

  • client.Config.LogPassword - Include FTP passwords in logs? Default: false.

Which logging frameworks can I use with FluentFTP?

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

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.

Example with Serilog

Nuget packages required:

Usage:

using FluentFTP;          // from NuGet package FluentFTP
using FluentFTP.Logging;  // from NuGet package FluentFTP.Logging

var builder = WebApplication.CreateBuilder(args);

var logger = new LoggerConfiguration()
    .MinimumLevel.Debug()
    .WriteTo.File("logs/Net6Tester.txt", rollingInterval: RollingInterval.Day)
    .CreateLogger();

client.Logger = new FtpLogAdapter(logger);

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