继承log4.net的类
2016-04-04 08:22
183 查看
using System; using System.Diagnostics; [assembly: log4net.Config.XmlConfigurator(Watch = true)] namespace Hbl.Core { public static class Log { /// <summary> /// 一般错误 /// </summary> /// <param name="message">消息</param> public static void Error(object message) { log4net.ILog log = log4net.LogManager.GetLogger(GetCurrentMethodFullName()); log.Error(message); } /// <summary> /// 一般错误 /// </summary> /// <param name="message">消息</param> /// <param name="exception">异常</param> public static void Error(object message, Exception exception) { log4net.ILog log = log4net.LogManager.GetLogger(GetCurrentMethodFullName()); log.Error(message, exception); } /// <summary> /// 信息 /// </summary> /// <param name="message">消息</param> public static void Info(object message) { log4net.ILog log = log4net.LogManager.GetLogger(GetCurrentMethodFullName()); log.Info(message); } /// <summary> /// 信息 /// </summary> /// <param name="message">消息</param> /// <param name="exception">异常</param> public static void Info(object message, Exception ex) { log4net.ILog log = log4net.LogManager.GetLogger(GetCurrentMethodFullName()); log.Info(message, ex); } /// <summary> /// 警告 /// </summary> /// <param name="message">消息</param> public static void Warn(object message) { log4net.ILog log = log4net.LogManager.GetLogger(GetCurrentMethodFullName()); log.Warn(message); } /// <summary> /// 警告 /// </summary> /// <param name="message">消息</param> /// <param name="exception">异常</param> public static void Warn(object message, Exception ex) { log4net.ILog log = log4net.LogManager.GetLogger(GetCurrentMethodFullName()); log.Warn(message, ex); } /// <summary> /// 调试 /// </summary> /// <param name="message">消息</param> public static void Debug(object message) { log4net.ILog log = log4net.LogManager.GetLogger(GetCurrentMethodFullName()); log.Debug(message); } /// <summary> /// 调试 /// </summary> /// <param name="message">消息</param> /// <param name="exception">异常</param> 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; } } } }
相关文章推荐
- [LeetCode] Longest Substring with At Most K Distinct Characters 最多有K个不同字符的最长子串
- 算法备忘录——基础数据结构与复杂度
- android studio导入背景图片,改变图标,定时退出三个操作
- 30分钟LINQ教程(0)
- SQLIO 磁盘測试工具參考
- AutoMapperHelper
- Activiti 删除key值相同的所有不同版本的流程定义
- python web框架——扩展Django&tornado
- 在CentOS安装PHP5.6
- [LeetCode 267] Palindrome Permutation II
- 设置按钮居中
- 开根号
- 按钮的监听和touch方法
- storyboard的根控制器在这个时候才会添加到窗口
- 不能直接给self.center.x赋值
- 初始化方法awakeFromNib,initWithFrame
- iOS Orientation 屏幕旋转
- QQ粘性效果计算原理
- layoutSubViews
- 关于DBA_TABLES中SECONDARY列的含义