NLogLogger.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. //using System;
  2. //using System.Diagnostics;
  3. //using NLog;
  4. //namespace Xilium.CefGlue.Helpers.Log
  5. //{
  6. // public interface ILogInitializer
  7. // {
  8. // Logger CreateLogger();
  9. // }
  10. // public class NLogLogger : ILogger
  11. // {
  12. // private readonly object _syncObject = new object();
  13. // private readonly ILogInitializer _logInitializer;
  14. // private volatile Logger _log = null;
  15. // private class CurrentLogInitilizer : ILogInitializer
  16. // {
  17. // public Logger CreateLogger()
  18. // {
  19. // return GetCurrentLogger();
  20. // }
  21. // }
  22. // private class NamedLogInitilizer : ILogInitializer
  23. // {
  24. // private readonly string _loggerName;
  25. // internal NamedLogInitilizer(string loggerName)
  26. // {
  27. // _loggerName = loggerName;
  28. // }
  29. // public Logger CreateLogger()
  30. // {
  31. // return LogManager.GetLogger(_loggerName);
  32. // }
  33. // }
  34. // private class TypeLogInitilizer : ILogInitializer
  35. // {
  36. // private readonly Type _type;
  37. // public TypeLogInitilizer(Type type)
  38. // {
  39. // _type = type;
  40. // }
  41. // public Logger CreateLogger()
  42. // {
  43. // return LogManager.GetCurrentClassLogger(_type);
  44. // }
  45. // }
  46. // private Logger Log
  47. // {
  48. // get
  49. // {
  50. // lock (_syncObject)
  51. // {
  52. // if (_log == null)
  53. // {
  54. // _log = _logInitializer.CreateLogger();
  55. // }
  56. // return _log;
  57. // }
  58. // }
  59. // }
  60. // public NLogLogger(ILogInitializer logInitializer)
  61. // {
  62. // _logInitializer = logInitializer;
  63. // }
  64. // public NLogLogger()
  65. // : this(new CurrentLogInitilizer())
  66. // {
  67. // }
  68. // public NLogLogger(Logger log)
  69. // {
  70. // _log = log;
  71. // _logInitializer = null;
  72. // }
  73. // public NLogLogger(string loggerName)
  74. // : this(new NamedLogInitilizer(loggerName))
  75. // {
  76. // }
  77. // public NLogLogger(Type type)
  78. // : this(new TypeLogInitilizer(type))
  79. // {
  80. // }
  81. // private static Logger GetCurrentLogger()
  82. // {
  83. // string loggerName;
  84. // Type declaringType;
  85. // int framesToSkip = 1;
  86. // do
  87. // {
  88. // var frame = new StackFrame(framesToSkip, false);
  89. // var method = frame.GetMethod();
  90. // declaringType = method.DeclaringType;
  91. // if (declaringType == null)
  92. // {
  93. // loggerName = method.Name;
  94. // break;
  95. // }
  96. // framesToSkip++;
  97. // loggerName = declaringType.FullName;
  98. // } while (declaringType.Module.Name.Equals("mscorlib.dll", StringComparison.OrdinalIgnoreCase));
  99. // return LogManager.GetLogger(loggerName);
  100. // }
  101. // public static ILogger GetLogger()
  102. // {
  103. // return new NLogLogger(GetCurrentLogger());
  104. // }
  105. // public void TraceException(string message, Exception exception)
  106. // {
  107. // Log.TraceException(message, exception);
  108. // }
  109. // public void Trace(string message, params object[] args)
  110. // {
  111. // Log.Trace(message, args);
  112. // }
  113. // public void DebugException(string message, Exception exception)
  114. // {
  115. // Log.DebugException(message, exception);
  116. // }
  117. // public void Debug(string message, params object[] args)
  118. // {
  119. // Log.Debug(message, args);
  120. // }
  121. // public void ErrorException(string message, Exception exception)
  122. // {
  123. // Log.ErrorException(message, exception);
  124. // }
  125. // public void Error(string message, params object[] args)
  126. // {
  127. // Log.Error(message, args);
  128. // }
  129. // public void FatalException(string message, Exception exception)
  130. // {
  131. // Log.FatalException(message, exception);
  132. // }
  133. // public void Fatal(string message, params object[] args)
  134. // {
  135. // Log.Fatal(message, args);
  136. // }
  137. // public void InfoException(string message, Exception exception)
  138. // {
  139. // Log.InfoException(message, exception);
  140. // }
  141. // public void Info(string message, params object[] args)
  142. // {
  143. // Log.Info(message, args);
  144. // }
  145. // public void WarnException(string message, Exception exception)
  146. // {
  147. // Log.WarnException(message, exception);
  148. // }
  149. // public void Warn(string message, params object[] args)
  150. // {
  151. // Log.Warn(message, args);
  152. // }
  153. // public bool IsTraceEnabled
  154. // {
  155. // get
  156. // {
  157. // return Log.IsTraceEnabled;
  158. // }
  159. // }
  160. // public bool IsDebugEnabled
  161. // {
  162. // get
  163. // {
  164. // return Log.IsDebugEnabled;
  165. // }
  166. // }
  167. // public bool IsErrorEnabled
  168. // {
  169. // get
  170. // {
  171. // return Log.IsErrorEnabled;
  172. // }
  173. // }
  174. // public bool IsFatalEnabled
  175. // {
  176. // get
  177. // {
  178. // return Log.IsFatalEnabled;
  179. // }
  180. // }
  181. // public bool IsInfoEnabled
  182. // {
  183. // get
  184. // {
  185. // return Log.IsInfoEnabled;
  186. // }
  187. // }
  188. // public bool IsWarnEnabled
  189. // {
  190. // get
  191. // {
  192. // return Log.IsWarnEnabled;
  193. // }
  194. // }
  195. // }
  196. //}