using System;using System.Diagnostics;[assembly: log4net.Config.XmlConfigurator(Watch = true)]namespace Hbl.Core{ public static class Log { ////// 一般错误 /// /// 消息 public static void Error(object message) { log4net.ILog log = log4net.LogManager.GetLogger(GetCurrentMethodFullName()); log.Error(message); } ////// 一般错误 /// /// 消息 /// 异常 public static void Error(object message, Exception exception) { log4net.ILog log = log4net.LogManager.GetLogger(GetCurrentMethodFullName()); log.Error(message, exception); } ////// 信息 /// /// 消息 public static void Info(object message) { log4net.ILog log = log4net.LogManager.GetLogger(GetCurrentMethodFullName()); log.Info(message); } ////// 信息 /// /// 消息 /// 异常 public static void Info(object message, Exception ex) { log4net.ILog log = log4net.LogManager.GetLogger(GetCurrentMethodFullName()); log.Info(message, ex); } ////// 警告 /// /// 消息 public static void Warn(object message) { log4net.ILog log = log4net.LogManager.GetLogger(GetCurrentMethodFullName()); log.Warn(message); } ////// 警告 /// /// 消息 /// 异常 public static void Warn(object message, Exception ex) { log4net.ILog log = log4net.LogManager.GetLogger(GetCurrentMethodFullName()); log.Warn(message, ex); } ////// 调试 /// /// 消息 public static void Debug(object message) { log4net.ILog log = log4net.LogManager.GetLogger(GetCurrentMethodFullName()); log.Debug(message); } ////// 调试 /// /// 消息 /// 异常 public static void Debug(object message, Exception ex) { log4net.ILog log = log4net.LogManager.GetLogger(GetCurrentMethodFullName()); log.Debug(message, ex); } static string GetCurrentMethodFullName() { try { int depth = 2; StackTrace st = new StackTrace(); int maxFrames = st.GetFrames().Length; StackFrame sf; string methodName, className; Type classType; do { sf = st.GetFrame(depth++); classType = sf.GetMethod().DeclaringType; className = classType.ToString(); } while (className.EndsWith("Exception") && depth < maxFrames); methodName = sf.GetMethod().Name; return className + "." + methodName; } catch { return null; } } }}