aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common/Logging/Logger.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Common/Logging/Logger.cs')
-rw-r--r--MediaBrowser.Common/Logging/Logger.cs203
1 files changed, 110 insertions, 93 deletions
diff --git a/MediaBrowser.Common/Logging/Logger.cs b/MediaBrowser.Common/Logging/Logger.cs
index 9ac02fe3e..33d6b7f73 100644
--- a/MediaBrowser.Common/Logging/Logger.cs
+++ b/MediaBrowser.Common/Logging/Logger.cs
@@ -1,93 +1,110 @@
-using System;
-using System.Diagnostics;
-using System.Text;
-using System.Threading;
-using MediaBrowser.Common.Kernel;
-
-namespace MediaBrowser.Common.Logging
-{
- public static class Logger
- {
- internal static IKernel Kernel { get; set; }
-
- public static void LogInfo(string message, params object[] paramList)
- {
- LogEntry(message, LogSeverity.Info, paramList);
- }
-
- public static void LogDebugInfo(string message, params object[] paramList)
- {
- LogEntry(message, LogSeverity.Debug, paramList);
- }
-
- public static void LogError(string message, params object[] paramList)
- {
- LogEntry(message, LogSeverity.Error, paramList);
- }
-
- public static void LogException(Exception ex, params object[] paramList)
- {
- LogException(string.Empty, ex, paramList);
- }
-
- public static void LogException(string message, Exception ex, params object[] paramList)
- {
- var builder = new StringBuilder();
-
- if (ex != null)
- {
- builder.AppendFormat("Exception. Type={0} Msg={1} StackTrace={3}{2}",
- ex.GetType().FullName,
- ex.Message,
- ex.StackTrace,
- Environment.NewLine);
- }
-
- message = FormatMessage(message, paramList);
-
- LogError(string.Format("{0} ( {1} )", message, builder));
- }
-
- public static void LogWarning(string message, params object[] paramList)
- {
- LogEntry(message, LogSeverity.Warning, paramList);
- }
-
- private static void LogEntry(string message, LogSeverity severity, params object[] paramList)
- {
- message = FormatMessage(message, paramList);
-
- Thread currentThread = Thread.CurrentThread;
-
- var row = new LogRow
- {
- Severity = severity,
- Message = message,
- ThreadId = currentThread.ManagedThreadId,
- ThreadName = currentThread.Name,
- Time = DateTime.Now
- };
-
- if (Kernel.Loggers != null)
- {
- foreach (var logger in Kernel.Loggers)
- {
- logger.LogEntry(row);
- }
- }
- }
-
- private static string FormatMessage(string message, params object[] paramList)
- {
- if (paramList != null)
- {
- for (int i = 0; i < paramList.Length; i++)
- {
- message = message.Replace("{" + i + "}", paramList[i].ToString());
- }
- }
-
- return message;
- }
- }
-}
+using MediaBrowser.Model.Logging;
+using System;
+
+namespace MediaBrowser.Common.Logging
+{
+ /// <summary>
+ /// Class Logger
+ /// </summary>
+ public static class Logger
+ {
+ /// <summary>
+ /// Gets or sets the logger instance.
+ /// </summary>
+ /// <value>The logger instance.</value>
+ internal static ILogger LoggerInstance { get; set; }
+
+ /// <summary>
+ /// Logs the info.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <param name="paramList">The param list.</param>
+ public static void LogInfo(string message, params object[] paramList)
+ {
+ LogEntry(message, LogSeverity.Info, null, paramList);
+ }
+
+ /// <summary>
+ /// Logs the debug info.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <param name="paramList">The param list.</param>
+ public static void LogDebugInfo(string message, params object[] paramList)
+ {
+ LogEntry(message, LogSeverity.Debug, null, paramList);
+ }
+
+ /// <summary>
+ /// Logs the error.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <param name="paramList">The param list.</param>
+ public static void LogError(string message, params object[] paramList)
+ {
+ LogEntry(message, LogSeverity.Error, null, paramList);
+ }
+
+ /// <summary>
+ /// Logs the exception.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <param name="ex">The ex.</param>
+ /// <param name="paramList">The param list.</param>
+ public static void LogException(string message, Exception ex, params object[] paramList)
+ {
+ LogEntry(message, LogSeverity.Error, ex, paramList);
+ }
+
+ /// <summary>
+ /// Fatals the exception.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <param name="ex">The ex.</param>
+ /// <param name="paramList">The param list.</param>
+ public static void FatalException(string message, Exception ex, params object[] paramList)
+ {
+ LogEntry(message, LogSeverity.Fatal, ex, paramList);
+ }
+
+ /// <summary>
+ /// Logs the warning.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <param name="paramList">The param list.</param>
+ public static void LogWarning(string message, params object[] paramList)
+ {
+ LogEntry(message, LogSeverity.Warn, null, paramList);
+ }
+
+ /// <summary>
+ /// Logs the entry.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <param name="level">The level.</param>
+ /// <param name="exception">The exception.</param>
+ /// <param name="paramList">The param list.</param>
+ private static void LogEntry(string message, LogSeverity level, Exception exception, params object[] paramList)
+ {
+ if (LoggerInstance == null)
+ {
+ return;
+ }
+
+ if (exception == null)
+ {
+ LoggerInstance.Log(level, message, paramList);
+ }
+ else
+ {
+ if (level == LogSeverity.Fatal)
+ {
+ LoggerInstance.FatalException(message, exception, paramList);
+ }
+ else
+ {
+ LoggerInstance.ErrorException(message, exception, paramList);
+ }
+ }
+ }
+ }
+}