首页 > 代码库 > 基于log4net的帮助类Log
基于log4net的帮助类Log
1 using log4net; 2 using System; 3 using System.Collections.Generic; 4 using System.Diagnostics; 5 using System.Linq; 6 using System.Web; 7 8 namespace TryLittle.Helper 9 {10 public static class Log11 {12 public static void Debug(object message)13 {14 LogManager.GetLogger(GetCurrentMethodFullName()).Debug(message);15 }16 17 public static void Debug(object message, Exception ex)18 {19 LogManager.GetLogger(GetCurrentMethodFullName()).Debug(message, ex);20 }21 22 public static void Error(object message)23 {24 LogManager.GetLogger(GetCurrentMethodFullName()).Error(message);25 }26 27 public static void Error(object message, Exception exception)28 {29 LogManager.GetLogger(GetCurrentMethodFullName()).Error(message, exception);30 }31 32 private static string GetCurrentMethodFullName()33 {34 try35 {36 StackFrame frame;37 string str2;38 int num = 2;39 StackTrace trace = new StackTrace();40 int length = trace.GetFrames().Length;41 do42 {43 frame = trace.GetFrame(num++);44 str2 = frame.GetMethod().DeclaringType.ToString();45 }46 while (str2.EndsWith("Exception") && (num < length));47 string name = frame.GetMethod().Name;48 return (str2 + "." + name);49 }50 catch51 {52 return null;53 }54 }55 56 public static void Info(object message)57 {58 LogManager.GetLogger(GetCurrentMethodFullName()).Info(message);59 }60 61 public static void Info(object message, Exception ex)62 {63 LogManager.GetLogger(GetCurrentMethodFullName()).Info(message, ex);64 }65 66 public static void Warn(object message)67 {68 LogManager.GetLogger(GetCurrentMethodFullName()).Warn(message);69 }70 71 public static void Warn(object message, Exception ex)72 {73 LogManager.GetLogger(GetCurrentMethodFullName()).Warn(message, ex);74 }75 76 }77 }
注意:如果要在项目中使用这个类一定先应用log4net
基于log4net的帮助类Log
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。