using log4net; using log4net.Config; using System; using System.Diagnostics; using System.IO; using System.Reflection; namespace Common { public abstract class LogHelper { private static ILog _LogAll = LogManager.GetLogger("LOGALL"); private static ILog _LogErr = LogManager.GetLogger("LOGERR"); private static ILog _LogDebug = LogManager.GetLogger("LOGDEBUG"); private static string GetMethodName(StackTrace trace) { MethodBase method = trace.GetFrame(1).GetMethod(); return (method.ReflectedType.Module.Name + " " + method.ReflectedType.Name + "." + method.Name).PadRight(50); } public static void Config(string configFile) { XmlConfigurator.ConfigureAndWatch(new FileInfo(configFile)); } public static void Error(string format, params object[] args) { LogHelper._LogErr.Error((object) string.Format("{0} {1}", (object) LogHelper.GetMethodName(new StackTrace()), (object) string.Format(format, args))); } public static void Info(string format, params object[] args) { LogHelper._LogAll.Info((object) string.Format("{0} {1}", (object) LogHelper.GetMethodName(new StackTrace()), (object) string.Format(format, args))); } public static void Warn(string format, params object[] args) { LogHelper._LogAll.Warn((object) string.Format("{0} {1}", (object) LogHelper.GetMethodName(new StackTrace()), (object) string.Format(format, args))); } public static void Debug(string format, params object[] args) { LogHelper._LogDebug.Debug((object) string.Format("{0} {1}", (object) LogHelper.GetMethodName(new StackTrace()), (object) string.Format(format, args))); } public static void Fatal(string format, params object[] args) { LogHelper._LogErr.Fatal((object) string.Format("{0} {1}", (object) LogHelper.GetMethodName(new StackTrace()), (object) string.Format(format, args))); } public static void Error(Exception e) { LogHelper._LogErr.Error((object) string.Format("{0} {1}\r\n{2}", (object) LogHelper.GetMethodName(new StackTrace()), (object) e.Message, (object) e.StackTrace)); } } }