Example #1
0
        public static void Error(string msg, Exception ex = null, bool console = false)
        {
            //调用堆栈
            StackTrace trace = new StackTrace();
            //调用本方法的方法
            MethodBase method   = trace.GetFrame(1).GetMethod();
            Type       type     = method.DeclaringType;
            string     methName = method != null ? method.Name : string.Empty;
            string     message  = "[" + methName + "(...)]" + msg;

            //var type = MethodBase.GetCurrentMethod().DeclaringType;
            log4net.ILog log = log4net.LogManager.GetLogger(type);
            log.ErrorExt(message, ex);

            if (console)
            {
                Console.WriteLine(msg);
            }
        }