Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Console logger for debugging.

  • Loading branch information...
commit d23e1ddf6c90120e790105b8424399bfd41848c1 1 parent 1b7bf61
@enyim authored
Showing with 205 additions and 192 deletions.
  1. +205 −192 Enyim.Caching/Logging/DiagnosticsLog.cs
View
397 Enyim.Caching/Logging/DiagnosticsLog.cs
@@ -26,256 +26,269 @@ public DiagnosticsLogFactory(string logPath)
ILog ILogFactory.GetLogger(string name)
{
- return new Log(name, this.writer);
+ return new TextWriterLog(name, this.writer);
}
ILog ILogFactory.GetLogger(Type type)
{
- return new Log(type.FullName, this.writer);
+ return new TextWriterLog(type.FullName, this.writer);
}
+ }
- #region [ ILog implementation ]
-
- private class Log : ILog
+ public class ConsoleLogFactory : ILogFactory
+ {
+ ILog ILogFactory.GetLogger(string name)
{
- private const string PrefixDebug = "DEBUG";
- private const string PrefixInfo = "INFO";
- private const string PrefixWarn = "WARN";
- private const string PrefixError = "ERROR";
- private const string PrefixFatal = "FATAL";
+ return new TextWriterLog(name, Console.Out);
+ }
- private TextWriter writer;
- private string name;
+ ILog ILogFactory.GetLogger(Type type)
+ {
+ return new TextWriterLog(type.FullName, Console.Out);
+ }
+ }
- public Log(string name, TextWriter writer)
- {
- this.name = name;
- this.writer = writer;
- }
+ #region [ ILog implementation ]
- private void Dump(string prefix, string message, params object[] args)
- {
- var line = String.Format("{0:yyyy-MM-dd' 'HH:mm:ss} [{1}] {2} {3} - ", DateTime.Now, prefix, Thread.CurrentThread.ManagedThreadId, this.name) + String.Format(message, args);
+ internal class TextWriterLog : ILog
+ {
+ private const string PrefixDebug = "DEBUG";
+ private const string PrefixInfo = "INFO";
+ private const string PrefixWarn = "WARN";
+ private const string PrefixError = "ERROR";
+ private const string PrefixFatal = "FATAL";
- lock (this.writer)
- {
- this.writer.WriteLine(line);
- this.writer.Flush();
- }
- }
+ private TextWriter writer;
+ private string name;
- private void Dump(string prefix, object message)
- {
- var line = String.Format("{0:yyyy-MM-dd' 'HH:mm:ss} [{1}] {2} {3} - {4}", DateTime.Now, prefix, Thread.CurrentThread.ManagedThreadId, this.name, message);
+ public TextWriterLog(string name, TextWriter writer)
+ {
+ this.name = name;
+ this.writer = writer;
+ }
- lock (this.writer)
- {
- this.writer.WriteLine(line);
- this.writer.Flush();
- }
- }
+ private void Dump(string prefix, string message, params object[] args)
+ {
+ var line = String.Format("{0:yyyy-MM-dd' 'HH:mm:ss} [{1}] {2} {3} - ", DateTime.Now, prefix, Thread.CurrentThread.ManagedThreadId, this.name) + String.Format(message, args);
- bool ILog.IsDebugEnabled
+ lock (this.writer)
{
- get { return true; }
+ this.writer.WriteLine(line);
+ this.writer.Flush();
}
+ }
- bool ILog.IsInfoEnabled
- {
- get { return true; }
- }
+ private void Dump(string prefix, object message)
+ {
+ var line = String.Format("{0:yyyy-MM-dd' 'HH:mm:ss} [{1}] {2} {3} - {4}", DateTime.Now, prefix, Thread.CurrentThread.ManagedThreadId, this.name, message);
- bool ILog.IsWarnEnabled
+ lock (this.writer)
{
- get { return true; }
+ this.writer.WriteLine(line);
+ this.writer.Flush();
}
+ }
- bool ILog.IsErrorEnabled
- {
- get { return true; }
- }
+ bool ILog.IsDebugEnabled
+ {
+ get { return true; }
+ }
- bool ILog.IsFatalEnabled
- {
- get { return true; }
- }
+ bool ILog.IsInfoEnabled
+ {
+ get { return true; }
+ }
- void ILog.Debug(object message)
- {
- this.Dump(PrefixDebug, message);
- }
+ bool ILog.IsWarnEnabled
+ {
+ get { return true; }
+ }
- void ILog.Debug(object message, Exception exception)
- {
- this.Dump(PrefixDebug, message + " - " + exception);
- }
+ bool ILog.IsErrorEnabled
+ {
+ get { return true; }
+ }
- void ILog.DebugFormat(string format, object arg0)
- {
- this.Dump(PrefixDebug, format, arg0);
- }
+ bool ILog.IsFatalEnabled
+ {
+ get { return true; }
+ }
- void ILog.DebugFormat(string format, object arg0, object arg1)
- {
- this.Dump(PrefixDebug, format, arg0, arg1);
- }
+ void ILog.Debug(object message)
+ {
+ this.Dump(PrefixDebug, message);
+ }
- void ILog.DebugFormat(string format, object arg0, object arg1, object arg2)
- {
- this.Dump(PrefixDebug, format, arg0, arg1, arg2);
- }
+ void ILog.Debug(object message, Exception exception)
+ {
+ this.Dump(PrefixDebug, message + " - " + exception);
+ }
- void ILog.DebugFormat(string format, params object[] args)
- {
- this.Dump(PrefixDebug, format, args);
- }
+ void ILog.DebugFormat(string format, object arg0)
+ {
+ this.Dump(PrefixDebug, format, arg0);
+ }
- void ILog.DebugFormat(IFormatProvider provider, string format, params object[] args)
- {
- this.Dump(PrefixDebug, String.Format(provider, format, args));
- }
+ void ILog.DebugFormat(string format, object arg0, object arg1)
+ {
+ this.Dump(PrefixDebug, format, arg0, arg1);
+ }
- void ILog.Info(object message)
- {
- this.Dump(PrefixInfo, message);
- }
+ void ILog.DebugFormat(string format, object arg0, object arg1, object arg2)
+ {
+ this.Dump(PrefixDebug, format, arg0, arg1, arg2);
+ }
- void ILog.Info(object message, Exception exception)
- {
- this.Dump(PrefixInfo, message + " - " + exception);
- }
+ void ILog.DebugFormat(string format, params object[] args)
+ {
+ this.Dump(PrefixDebug, format, args);
+ }
- void ILog.InfoFormat(string format, object arg0)
- {
- this.Dump(PrefixInfo, format, arg0);
- }
+ void ILog.DebugFormat(IFormatProvider provider, string format, params object[] args)
+ {
+ this.Dump(PrefixDebug, String.Format(provider, format, args));
+ }
- void ILog.InfoFormat(string format, object arg0, object arg1)
- {
- this.Dump(PrefixInfo, format, arg0, arg1);
- }
+ void ILog.Info(object message)
+ {
+ this.Dump(PrefixInfo, message);
+ }
- void ILog.InfoFormat(string format, object arg0, object arg1, object arg2)
- {
- this.Dump(PrefixInfo, format, arg0, arg1, arg2);
- }
+ void ILog.Info(object message, Exception exception)
+ {
+ this.Dump(PrefixInfo, message + " - " + exception);
+ }
- void ILog.InfoFormat(string format, params object[] args)
- {
- this.Dump(PrefixInfo, format, args);
- }
+ void ILog.InfoFormat(string format, object arg0)
+ {
+ this.Dump(PrefixInfo, format, arg0);
+ }
- void ILog.InfoFormat(IFormatProvider provider, string format, params object[] args)
- {
- this.Dump(PrefixInfo, String.Format(provider, format, args));
- }
+ void ILog.InfoFormat(string format, object arg0, object arg1)
+ {
+ this.Dump(PrefixInfo, format, arg0, arg1);
+ }
- void ILog.Warn(object message)
- {
- this.Dump(PrefixWarn, message);
- }
+ void ILog.InfoFormat(string format, object arg0, object arg1, object arg2)
+ {
+ this.Dump(PrefixInfo, format, arg0, arg1, arg2);
+ }
- void ILog.Warn(object message, Exception exception)
- {
- this.Dump(PrefixWarn, message + " - " + exception);
- }
+ void ILog.InfoFormat(string format, params object[] args)
+ {
+ this.Dump(PrefixInfo, format, args);
+ }
- void ILog.WarnFormat(string format, object arg0)
- {
- this.Dump(PrefixWarn, format, arg0);
- }
+ void ILog.InfoFormat(IFormatProvider provider, string format, params object[] args)
+ {
+ this.Dump(PrefixInfo, String.Format(provider, format, args));
+ }
- void ILog.WarnFormat(string format, object arg0, object arg1)
- {
- this.Dump(PrefixWarn, format, arg0, arg1);
- }
+ void ILog.Warn(object message)
+ {
+ this.Dump(PrefixWarn, message);
+ }
- void ILog.WarnFormat(string format, object arg0, object arg1, object arg2)
- {
- this.Dump(PrefixWarn, format, arg0, arg1, arg2);
- }
+ void ILog.Warn(object message, Exception exception)
+ {
+ this.Dump(PrefixWarn, message + " - " + exception);
+ }
- void ILog.WarnFormat(string format, params object[] args)
- {
- this.Dump(PrefixWarn, format, args);
- }
+ void ILog.WarnFormat(string format, object arg0)
+ {
+ this.Dump(PrefixWarn, format, arg0);
+ }
- void ILog.WarnFormat(IFormatProvider provider, string format, params object[] args)
- {
- this.Dump(PrefixWarn, String.Format(provider, format, args));
- }
+ void ILog.WarnFormat(string format, object arg0, object arg1)
+ {
+ this.Dump(PrefixWarn, format, arg0, arg1);
+ }
- void ILog.Error(object message)
- {
- this.Dump(PrefixError, message);
- }
+ void ILog.WarnFormat(string format, object arg0, object arg1, object arg2)
+ {
+ this.Dump(PrefixWarn, format, arg0, arg1, arg2);
+ }
- void ILog.Error(object message, Exception exception)
- {
- this.Dump(PrefixError, message + " - " + exception);
- }
+ void ILog.WarnFormat(string format, params object[] args)
+ {
+ this.Dump(PrefixWarn, format, args);
+ }
- void ILog.ErrorFormat(string format, object arg0)
- {
- this.Dump(PrefixError, format, arg0);
- }
+ void ILog.WarnFormat(IFormatProvider provider, string format, params object[] args)
+ {
+ this.Dump(PrefixWarn, String.Format(provider, format, args));
+ }
- void ILog.ErrorFormat(string format, object arg0, object arg1)
- {
- this.Dump(PrefixError, format, arg0, arg1);
- }
+ void ILog.Error(object message)
+ {
+ this.Dump(PrefixError, message);
+ }
- void ILog.ErrorFormat(string format, object arg0, object arg1, object arg2)
- {
- this.Dump(PrefixError, format, arg0, arg1, arg2);
- }
+ void ILog.Error(object message, Exception exception)
+ {
+ this.Dump(PrefixError, message + " - " + exception);
+ }
- void ILog.ErrorFormat(string format, params object[] args)
- {
- this.Dump(PrefixError, format, args);
- }
+ void ILog.ErrorFormat(string format, object arg0)
+ {
+ this.Dump(PrefixError, format, arg0);
+ }
- void ILog.ErrorFormat(IFormatProvider provider, string format, params object[] args)
- {
- this.Dump(PrefixError, String.Format(provider, format, args));
- }
+ void ILog.ErrorFormat(string format, object arg0, object arg1)
+ {
+ this.Dump(PrefixError, format, arg0, arg1);
+ }
- void ILog.Fatal(object message)
- {
- this.Dump(PrefixFatal, message);
- }
+ void ILog.ErrorFormat(string format, object arg0, object arg1, object arg2)
+ {
+ this.Dump(PrefixError, format, arg0, arg1, arg2);
+ }
- void ILog.Fatal(object message, Exception exception)
- {
- this.Dump(PrefixFatal, message + " - " + exception);
- }
+ void ILog.ErrorFormat(string format, params object[] args)
+ {
+ this.Dump(PrefixError, format, args);
+ }
- void ILog.FatalFormat(string format, object arg0)
- {
- this.Dump(PrefixFatal, format, arg0);
- }
+ void ILog.ErrorFormat(IFormatProvider provider, string format, params object[] args)
+ {
+ this.Dump(PrefixError, String.Format(provider, format, args));
+ }
- void ILog.FatalFormat(string format, object arg0, object arg1)
- {
- this.Dump(PrefixFatal, format, arg0, arg1);
- }
+ void ILog.Fatal(object message)
+ {
+ this.Dump(PrefixFatal, message);
+ }
- void ILog.FatalFormat(string format, object arg0, object arg1, object arg2)
- {
- this.Dump(PrefixFatal, format, arg0, arg1, arg2);
- }
+ void ILog.Fatal(object message, Exception exception)
+ {
+ this.Dump(PrefixFatal, message + " - " + exception);
+ }
- void ILog.FatalFormat(string format, params object[] args)
- {
- this.Dump(PrefixFatal, format, args);
- }
+ void ILog.FatalFormat(string format, object arg0)
+ {
+ this.Dump(PrefixFatal, format, arg0);
+ }
- void ILog.FatalFormat(IFormatProvider provider, string format, params object[] args)
- {
- this.Dump(PrefixFatal, String.Format(provider, format, args));
- }
+ void ILog.FatalFormat(string format, object arg0, object arg1)
+ {
+ this.Dump(PrefixFatal, format, arg0, arg1);
+ }
+
+ void ILog.FatalFormat(string format, object arg0, object arg1, object arg2)
+ {
+ this.Dump(PrefixFatal, format, arg0, arg1, arg2);
}
- #endregion
+ void ILog.FatalFormat(string format, params object[] args)
+ {
+ this.Dump(PrefixFatal, format, args);
+ }
+
+ void ILog.FatalFormat(IFormatProvider provider, string format, params object[] args)
+ {
+ this.Dump(PrefixFatal, String.Format(provider, format, args));
+ }
}
+
+ #endregion
}
Please sign in to comment.
Something went wrong with that request. Please try again.