| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 | 
							- using System;
 
- using System.Text;
 
- using log4net;
 
- namespace Logger
 
- {
 
-     
 
-     
 
-     
 
-     public class LogHelper
 
-     {
 
-         
 
-         
 
-         
 
-         private static ILog _log;
 
-         
 
-         
 
-         
 
-         
 
-         public LogHelper(Type type)
 
-         {
 
-             
 
-             
 
-             _log = LogManager.GetLogger(type);
 
-         }
 
-         
 
-         
 
-         
 
-         
 
-         public LogHelper(string typeName)
 
-         {
 
-             
 
-             
 
-             _log = LogManager.GetLogger(typeName);
 
-         }
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         public static ILog GetLogger(string type)
 
-         {
 
-             return LogManager.GetLogger(type);
 
-         }
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         public static void Logger(Type type, string desc, ErrorHandel errorHandel, Action tryHandel,Action<Exception> catchHandel = null, Action finallHandel = null)
 
-         {
 
-             ILog log = LogManager.GetLogger(type);
 
-             try
 
-             {
 
-                 
 
-                 tryHandel();
 
-             }
 
-             catch (Exception exception)
 
-             {
 
-                 
 
-                 
 
-                 
 
-                 
 
-                 
 
-                 
 
-                 
 
-                 
 
-                 log.Error(desc + "发生异常。", exception);
 
-                 if (catchHandel != null)
 
-                 {
 
-                     catchHandel(exception);
 
-                 }
 
-                 if (errorHandel == ErrorHandel.Throw)
 
-                 {
 
-                     throw;
 
-                 }
 
-             }
 
-             finally
 
-             {
 
-                 if (finallHandel != null)
 
-                 {
 
-                     finallHandel();
 
-                 }
 
-             }
 
-         }
 
-         
 
-         #region 1、Info
 
-         
 
-         
 
-         
 
-         
 
-         public void Info(string info)
 
-         {
 
-             _log.Info(info);
 
-         }
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         public void InfoFormat(string format, params object[] args)
 
-         {
 
-             _log.InfoFormat(format, args);
 
-         }
 
-         #endregion
 
-         #region 2、Error
 
-         
 
-         
 
-         
 
-         
 
-         public void Error(string info)
 
-         {
 
-             _log.Error(info);
 
-         }
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         public void Error(string info, Exception exception)
 
-         {
 
-             _log.Error(info, exception);
 
-         }
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         public void ErrorFormat(string format, params object[] args)
 
-         {
 
-             _log.ErrorFormat(format, args);
 
-         }
 
-         #endregion
 
-         #region 3、Debug
 
-         
 
-         
 
-         
 
-         
 
-         public void Debug(string info)
 
-         {
 
-             _log.Debug(info);
 
-         }
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         public void DebugFormat(string format, params object[] args)
 
-         {
 
-             _log.DebugFormat(format, args);
 
-         }
 
-         #endregion
 
-         #region 4、Warn
 
-         
 
-         
 
-         
 
-         
 
-         public void Warn(string info)
 
-         {
 
-             _log.Warn(info);
 
-         }
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         public void WarnFormat(string format, params object[] args)
 
-         {
 
-             _log.WarnFormat(format, args);
 
-         }
 
-         #endregion
 
-     }
 
- }
 
 
  |