2012-07-12 06:55:27 +00:00
|
|
|
|
using System;
|
2012-09-18 19:33:57 +00:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using MediaBrowser.Common.Kernel;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-31 03:38:00 +00:00
|
|
|
|
namespace MediaBrowser.Common.Logging
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
|
|
|
|
public static class Logger
|
|
|
|
|
{
|
2012-09-18 19:33:57 +00:00
|
|
|
|
internal static IKernel Kernel { get; set; }
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
|
|
|
|
public static void LogInfo(string message, params object[] paramList)
|
|
|
|
|
{
|
2012-09-18 19:33:57 +00:00
|
|
|
|
LogEntry(message, LogSeverity.Info, paramList);
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void LogDebugInfo(string message, params object[] paramList)
|
|
|
|
|
{
|
2012-09-18 19:33:57 +00:00
|
|
|
|
LogEntry(message, LogSeverity.Debug, paramList);
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void LogError(string message, params object[] paramList)
|
|
|
|
|
{
|
2012-09-18 19:33:57 +00:00
|
|
|
|
LogEntry(message, LogSeverity.Error, paramList);
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-11 03:06:45 +00:00
|
|
|
|
public static void LogException(Exception ex, params object[] paramList)
|
|
|
|
|
{
|
|
|
|
|
LogException(string.Empty, ex, paramList);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-12 06:55:27 +00:00
|
|
|
|
public static void LogException(string message, Exception ex, params object[] paramList)
|
|
|
|
|
{
|
2012-09-18 19:33:57 +00:00
|
|
|
|
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));
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void LogWarning(string message, params object[] paramList)
|
|
|
|
|
{
|
2012-09-18 19:33:57 +00:00
|
|
|
|
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;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|