Debug.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Diagnostics;
  3. using System.Net.FtpClient;
  4. namespace Examples {
  5. /// <summary>
  6. /// Example for logging server transactions for use in debugging problems. If DEBUG
  7. /// is defined this information is logged via System.Diagnostics.Debug.Write() as well
  8. /// so you'll the same information in your Visual Studio Output window
  9. /// </summary>
  10. public static class DebugExample {
  11. /// <summary>
  12. /// Log to a console window
  13. /// </summary>
  14. static void LogToConsole() {
  15. FtpTrace.AddListener(new ConsoleTraceListener());
  16. // now use System.Net.FtpCLient as usual and the server transactions
  17. // will be written to the Console window.
  18. }
  19. /// <summary>
  20. /// Log to a text file
  21. /// </summary>
  22. static void LogToFile() {
  23. FtpTrace.AddListener(new TextWriterTraceListener("log_file.txt"));
  24. // now use System.Net.FtpCLient as usual and the server transactions
  25. // will be written to the specified log file.
  26. }
  27. /// <summary>
  28. /// Custom trace listener class that can log the transaction
  29. /// however you want.
  30. /// </summary>
  31. class CustomTraceListener : TraceListener {
  32. public override void Write(string message) {
  33. Console.Write(message);
  34. }
  35. public override void WriteLine(string message) {
  36. Console.WriteLine(message);
  37. }
  38. }
  39. /// <summary>
  40. /// Log to a custom TraceListener
  41. /// </summary>
  42. static void LogToCustomListener() {
  43. FtpTrace.AddListener(new CustomTraceListener());
  44. }
  45. }
  46. }