Logger.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using MediaBrowser.Model.Logging;
  2. using System;
  3. namespace MediaBrowser.Common.Logging
  4. {
  5. /// <summary>
  6. /// Class Logger
  7. /// </summary>
  8. public static class Logger
  9. {
  10. /// <summary>
  11. /// Gets or sets the logger instance.
  12. /// </summary>
  13. /// <value>The logger instance.</value>
  14. internal static ILogger LoggerInstance { get; set; }
  15. /// <summary>
  16. /// Logs the info.
  17. /// </summary>
  18. /// <param name="message">The message.</param>
  19. /// <param name="paramList">The param list.</param>
  20. public static void LogInfo(string message, params object[] paramList)
  21. {
  22. LogEntry(message, LogSeverity.Info, null, paramList);
  23. }
  24. /// <summary>
  25. /// Logs the debug info.
  26. /// </summary>
  27. /// <param name="message">The message.</param>
  28. /// <param name="paramList">The param list.</param>
  29. public static void LogDebugInfo(string message, params object[] paramList)
  30. {
  31. LogEntry(message, LogSeverity.Debug, null, paramList);
  32. }
  33. /// <summary>
  34. /// Logs the exception.
  35. /// </summary>
  36. /// <param name="message">The message.</param>
  37. /// <param name="ex">The ex.</param>
  38. /// <param name="paramList">The param list.</param>
  39. public static void LogException(string message, Exception ex, params object[] paramList)
  40. {
  41. LogEntry(message, LogSeverity.Error, ex, paramList);
  42. }
  43. /// <summary>
  44. /// Logs the warning.
  45. /// </summary>
  46. /// <param name="message">The message.</param>
  47. /// <param name="paramList">The param list.</param>
  48. public static void LogWarning(string message, params object[] paramList)
  49. {
  50. LogEntry(message, LogSeverity.Warn, null, paramList);
  51. }
  52. /// <summary>
  53. /// Logs the entry.
  54. /// </summary>
  55. /// <param name="message">The message.</param>
  56. /// <param name="level">The level.</param>
  57. /// <param name="exception">The exception.</param>
  58. /// <param name="paramList">The param list.</param>
  59. private static void LogEntry(string message, LogSeverity level, Exception exception, params object[] paramList)
  60. {
  61. if (LoggerInstance == null)
  62. {
  63. return;
  64. }
  65. if (exception == null)
  66. {
  67. LoggerInstance.Log(level, message, paramList);
  68. }
  69. else
  70. {
  71. if (level == LogSeverity.Fatal)
  72. {
  73. LoggerInstance.FatalException(message, exception, paramList);
  74. }
  75. else
  76. {
  77. LoggerInstance.ErrorException(message, exception, paramList);
  78. }
  79. }
  80. }
  81. }
  82. }