INetworkLogger.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. namespace Microsoft.Xna.Framework.Net
  3. {
  4. /// <summary>
  5. /// Interface for network logging.
  6. /// </summary>
  7. public interface INetworkLogger
  8. {
  9. /// <summary>
  10. /// Logs an informational message.
  11. /// </summary>
  12. void LogInfo(string message);
  13. /// <summary>
  14. /// Logs a warning message.
  15. /// </summary>
  16. void LogWarning(string message);
  17. /// <summary>
  18. /// Logs an error message with optional exception.
  19. /// </summary>
  20. void LogError(string message, Exception ex = null);
  21. }
  22. /// <summary>
  23. /// Console-based network logger implementation.
  24. /// </summary>
  25. public class ConsoleNetworkLogger : INetworkLogger
  26. {
  27. public void LogInfo(string message)
  28. {
  29. Console.WriteLine($"[NET] {message}");
  30. }
  31. public void LogWarning(string message)
  32. {
  33. Console.WriteLine($"[NET-WARN] {message}");
  34. }
  35. public void LogError(string message, Exception ex = null)
  36. {
  37. Console.WriteLine($"[NET-ERROR] {message}");
  38. if (ex != null)
  39. Console.WriteLine($" {ex}");
  40. }
  41. }
  42. /// <summary>
  43. /// Null logger that does nothing (for production builds).
  44. /// </summary>
  45. public class NullNetworkLogger : INetworkLogger
  46. {
  47. public void LogInfo(string message) { }
  48. public void LogWarning(string message) { }
  49. public void LogError(string message, Exception ex = null) { }
  50. }
  51. }