Log4net在类库中调用写法

 public class LogHelper
    {
        public static Type type;
        public static ILog Logger
        {
            get
            {
                ILog log = log4net.LogManager.GetLogger(type);
                return log;
            }
        }
    }
    public class Logger
    {
        private log4net.ILog log;

        public Logger()
        {
            StackTrace st = new StackTrace(1, true);
            StackFrame[] stFrames = st.GetFrames();
            Type t = stFrames[0].GetMethod().DeclaringType;
            log = log4net.LogManager.GetLogger(t);
        }

        public void debug(string format, params object[] args)
        {
            log.DebugFormat(format, args);
        }

        public void info(string format, params object[] args)
        {
            log.InfoFormat(format, args);
        }

        public void error(string format, params object[] args)
        {
            log.ErrorFormat(format, args);
        }

        public void fatal(string format, params object[] args)
        {
            log.FatalFormat(format, args);
        }
    }

你可能感兴趣的:(log)