Repository navigation
Logging
-
client.OnLogEvent - A property of
FtpClient. Assign this to a callback that will be fired every time a message is logged. -
FtpTrace.LogFunctions - Include high-level function calls in logs? Default: true.
-
FtpTrace.LogIP - Include server IP addresses in logs? Default: true.
-
FtpTrace.LogUserName - Include FTP usernames in logs? Default: true.
-
FtpTrace.LogPassword - Include FTP passwords in logs? Default: false.
-
FtpTrace.LogPrefix - Log all messages prefixed with "FluentFTP". Default: false.
-
FtpTrace.WriteLine - Log a message or error to all registered listeners.
-
FtpTrace.LogToConsole - Should FTP communication be be logged to the console? Default: false.
-
FtpTrace.LogToFile - Set this to a file path to append all FTP communication to it. Default: false.
.NET Framework only
-
FtpTrace.FlushOnWrite - Flush trace listeners after writing each command. Default: true.
-
FtpTrace.AddListener - Add a logger to the system. Learn more
-
FtpTrace.RemoveListener - Remove a logger from the system.
Do this at program startup (since its static it takes effect for all FtpClient instances.)
.NET Framework version
FtpTrace.AddListener(new ConsoleTraceListener());
FtpTrace.LogUserName = false; // hide FTP user names
FtpTrace.LogPassword = false; // hide FTP passwords
FtpTrace.LogIP = false; // hide FTP server IP addresses.NET Standard version
FtpTrace.LogToConsole = true;
FtpTrace.LogUserName = false; // hide FTP user names
FtpTrace.LogPassword = false; // hide FTP passwords
FtpTrace.LogIP = false; // hide FTP server IP addressesAlternatively you can hook onto client.OnLogEvent to get a callback every time a message is logged in the context of an individual FtpClient instance.
Do this at program startup (since its static it takes effect for all FtpClient instances.)
.NET Framework version
FtpTrace.AddListener(new TextWriterTraceListener("log_file.txt"));
FtpTrace.LogUserName = false; // hide FTP user names
FtpTrace.LogPassword = false; // hide FTP passwords
FtpTrace.LogIP = false; // hide FTP server IP addresses.NET Standard version
FtpTrace.LogToFile = "log_file.txt";
FtpTrace.LogUserName = false; // hide FTP user names
FtpTrace.LogPassword = false; // hide FTP passwords
FtpTrace.LogIP = false; // hide FTP server IP addressesThis is the recommended configuration for a production server. Only supported in .NET Framework version.
Do this at program startup (since its static it takes effect for all FtpClient instances.)
FtpTrace.LogFunctions = false;
FtpTrace.AddListener(new TextWriterTraceListener("log_file.txt"){
Filter = new EventTypeFilter(SourceLevels.Error)
});Do this at program startup (since its static it takes effect for all FtpClient instances.)
FtpTrace.LogFunctions = false;Use these settings to control what data is included in the logs:
-
FtpTrace.LogUserName- Log FTP user names? -
FtpTrace.LogPassword- Log FTP passwords? -
FtpTrace.LogIP- Log FTP server IP addresses?
FluentFTP has a built-in TraceSource named "FluentFTP" that can be used for debugging and logging purposes. This is currently available for all .NET Framework versions except for .NET Standard. Any implementation of TraceListener can be attached to the library either programmatically or via configuration in your app.config or web.config file. This will allow for direct logging or forwarding to third-party logging frameworks.
Most tracing messages are of type Verbose or Information and can typically be ignored unless debugging. Most ignored exceptions are classified as Warning, but methods that return boolean for success/failure will log the failure reasons with the Error level. If you are using .NET Standard and the DEBUG flag is set, then all logging messages will be issued via Debug.Write(message).
Attaching TraceListener in code:
TraceListener console = ConsoleTraceListener() {
Filter = new EventTypeFilter(SourceLevels.Verbose | SourceLevels.ActivityTracking)
};
FtpTrace.AddListener(console);Attaching via configuration file:
<system.diagnostics>
<trace autoflush="true">trace>
<sources>
<source name="FluentFTP">
<listeners>
<clear />
<add name="console />
" file" />
" myLogger" />
" nlog" />
" console" type="System.Diagnostics.ConsoleTraceListener" />
" file" type="System.Diagnostics.TextWriterTraceListener
initializeData="outputFile.log">
<filter type="System.Diagnostics.EventTypeFilter" initializeData="Error" />
add>
<add name="custom" type="MyNamespace.MyCustomTraceListener />
" nlog" type="NLog.NLogTraceListener, NLog" />
- Auto Connection
- Auto Reconnection
- FTP(S) Connection
- FTP(S) Connection using GnuTLS
- FTP(S) Connection using BouncyCastle
- FTPS Proxies
- Custom Servers
- Custom Commands
- v40 Migration Guide