2012-07-12 06:55:27 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
2012-07-30 13:44:28 +00:00
|
|
|
|
namespace MediaBrowser.Logging
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-30 13:44:28 +00:00
|
|
|
|
public abstract class BaseLogger : IDisposable
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
|
|
|
|
public LogSeverity LogSeverity { get; set; }
|
|
|
|
|
|
|
|
|
|
public void LogInfo(string message, params object[] paramList)
|
|
|
|
|
{
|
|
|
|
|
LogEntry(message, LogSeverity.Info, paramList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LogDebugInfo(string message, params object[] paramList)
|
|
|
|
|
{
|
|
|
|
|
LogEntry(message, LogSeverity.Debug, paramList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LogError(string message, params object[] paramList)
|
|
|
|
|
{
|
|
|
|
|
LogEntry(message, LogSeverity.Error, paramList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LogException(string message, Exception exception, params object[] paramList)
|
|
|
|
|
{
|
|
|
|
|
StringBuilder builder = new StringBuilder();
|
2012-07-30 13:44:28 +00:00
|
|
|
|
|
2012-07-12 06:55:27 +00:00
|
|
|
|
if (exception != null)
|
|
|
|
|
{
|
2012-07-30 13:44:28 +00:00
|
|
|
|
builder.AppendFormat("Exception. Type={0} Msg={1} StackTrace={3}{2}",
|
2012-07-12 06:55:27 +00:00
|
|
|
|
exception.GetType().FullName,
|
|
|
|
|
exception.Message,
|
|
|
|
|
exception.StackTrace,
|
2012-07-30 13:44:28 +00:00
|
|
|
|
Environment.NewLine);
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
message = string.Format(message, paramList);
|
|
|
|
|
|
|
|
|
|
LogError(string.Format("{0} ( {1} )", message, builder));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LogWarning(string message, params object[] paramList)
|
|
|
|
|
{
|
|
|
|
|
LogEntry(message, LogSeverity.Warning, paramList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LogEntry(string message, LogSeverity severity, params object[] paramList)
|
|
|
|
|
{
|
|
|
|
|
if (severity < LogSeverity) return;
|
|
|
|
|
|
|
|
|
|
message = string.Format(message, paramList);
|
|
|
|
|
|
|
|
|
|
Thread currentThread = Thread.CurrentThread;
|
|
|
|
|
|
|
|
|
|
LogRow row = new LogRow()
|
|
|
|
|
{
|
|
|
|
|
Severity = severity,
|
|
|
|
|
Message = message,
|
|
|
|
|
Category = string.Empty,
|
|
|
|
|
ThreadId = currentThread.ManagedThreadId,
|
2012-07-30 13:44:28 +00:00
|
|
|
|
//ThreadName = currentThread.Name,
|
2012-07-12 06:55:27 +00:00
|
|
|
|
Time = DateTime.Now
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LogEntry(row);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-30 13:44:28 +00:00
|
|
|
|
public virtual void Dispose()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-12 06:55:27 +00:00
|
|
|
|
protected abstract void LogEntry(LogRow row);
|
|
|
|
|
}
|
|
|
|
|
}
|