Logging in Ftp.dll
To enable logging for Ftp.dll .NET FTP and FTPS component you only need to add the following line before you connect:
// C# version: Limilabs.FTP.Log.Enabled = true;
' VB.NET version: Limilabs.FTP.Log.Enabled = True
You can observe the log output by:
- looking at the Visual Studio’s output window (View/Output/’Show output from’: Debug)
- subscribing to Log.WriteLine event
- defining custom listeners using your application’s config file (App.config or Web.config)
- using log4net
This is how the log looks like in the Visual Studio’s output window:
You can also enable logging using your application’s config file (App.config, Web.config):
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.diagnostics> <switches> <add name="Ftp.dll" value="Verbose" /> </switches> </system.diagnostics> </configuration>
If you are using the latest version of log4net.dll, Ftp.dll is going to use log4net instead of standard .NET System.Net.TraceSource class. Please refer to log4net manual on how to capture log entries.
Ftp.dll uses logger called “Ftp.dll” (_logger = LogManager.GetLogger(“Ftp.dll”)) and level Info (_logger.Info(message)) to log information.
Please remember that even when using log4net, you need to enable logging by setting “Limilabs.FTP.Log.Enabled = True” or by setting Ftp.dll trace switch in the config file (App.config, Web.config) to Verbose as shown above.
Log to file
You’ll need to define a TextWriterTraceListener that writes to a file and connect it with Ftp.dll trace source. The easiest solution is to modify your application’s config file (App.config, Web.config) accordingly:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.diagnostics> <trace autoflush="true"/> <switches> <add name="Ftp.dll" value="Verbose"/> </switches> <sources> <source name="Ftp.dll"> <listeners> <add name="FtpLogFile"/> </listeners> </source> </sources> <sharedListeners> <add name="FtpLogFile" type="System.Diagnostics.TextWriterTraceListener" initializeData="c:\ftp.log"/> </sharedListeners> </system.diagnostics> </configuration>
Log class exposes WriteLine event. You can use that event to subscribe your own logging library.
// C# Log.WriteLine += Console.WriteLine;
' VB.NET Log.WriteLine += Console.WriteLine