logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xalex <a...@pixafe.com>
Subject Wrapping Log4Net
Date Sat, 18 Jul 2009 20:53:58 GMT

Hi forum,

I would like to use log4net in a large .net development. because i have the
requirement to prepare a potential replacement of the log4net framework e.g.
against ms-enterprise library or against a newer version of log4net, i would
like to wrap this. My way to do it is straight forward: 
A single assembly references the log4net framework, offes the ILog and
LogManager classes, and all other projects reference only this wrapper (see
below).

This wrapper allows me to restrict the users on only the main functions
which are really needed and allows me to replace this framework,
potentially.

Now my question: When the ILog.Debug() Method is called, the output in the
logfile is wrong, because the LocationInfo used for this output corresponds
to the Wrapper and not to the code from which it is really called :-(

A: Is there an easy way to fix this problem?
B: Is there a better idea to wrap log4net
C: Is it true, that logging is only possible in DEBUG-Builds? When using the
release build, i dont get any output

Thanks 
Alex



Wrapper:
------------
    public interface ILog
    {
        bool IsDebugEnabled { get; }
        bool IsErrorEnabled { get; }
        bool IsFatalEnabled { get; }
        bool IsInfoEnabled { get; }
        bool IsWarnEnabled { get; }

        void Debug(object message);
        void Error(object message);
        void Fatal(object message);
        void Info(object message);
        void Warn(object message);
    }

    public static class LogManager
    {
        static LogManager()
        {
            XmlConfigurator.Configure( new
System.IO.FileInfo("c:/logger.xml")) ;
        }

        public static ILog GetLogger(Type type)
        {
            MyLog log = new MyLog(log4net.LogManager.GetLogger(type) );
            return log;
        }
    }

    public class MyLog :ILog
    {
        private log4net.ILog _log;

        public MyLog(log4net.ILog log) 
        {
            _log = log;
        }

        #region ILog Members

        public bool IsDebugEnabled
        {
            get { return _log.IsDebugEnabled; }
        }

        
        public void Debug(object message)
        {
            _log.Debug(message);
        }

   ...
}

-- 
View this message in context: http://www.nabble.com/Wrapping-Log4Net-tp24551728p24551728.html
Sent from the Log4net - Users mailing list archive at Nabble.com.


Mime
View raw message