Beispiel #1
0
        /// <summary>
        /// initializes the log system using the logfile argument
        /// </summary>
        private void  internalInit(String logfile)
        {
            // create a new logging domain
            ILoggerRepository domain = null;

            try {
                domain = log4net.LogManager.GetLoggerRepository(System.Reflection.Assembly.GetExecutingAssembly().FullName);
            } catch (log4net.spi.LogException) {
                // Do nothing, this is expected if the domain has not been created
            }

            // create and initialize the domain if it does not exist
            if (domain == null)
            {
                domain = log4net.LogManager.CreateDomain(System.Reflection.Assembly.GetExecutingAssembly().FullName);

                // create an appender for the domain
                RollingFileAppender appender = new RollingFileAppender();
                appender.Layout             = new PatternLayout("%d - %m%n");
                appender.File               = logfile;
                appender.AppendToFile       = true;
                appender.MaxSizeRollBackups = 1;
                appender.MaximumFileSize    = "100000";
                appender.ActivateOptions();

                // initialize/configure the domain
                log4net.Config.BasicConfigurator.Configure(domain, appender);
            }

            // create the category
            Object o = domain.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

            if (o is log4net.spi.ILogger)
            {
                this.logger = (log4net.spi.ILogger)domain.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
            }
            else
            {
                throw new System.Exception("got unexpected logger type: " + o.GetType().ToString());
            }
        }
Beispiel #2
0
        public virtual void Init(RuntimeServices rs)
        {
            rsvc = rs;

            // first see if there is a category specified and just use that - it allows
            // the application to make us use an existing logger
            String categoryname = (String)rsvc.getProperty("runtime.log.logsystem.log4net.category");

            if (categoryname != null)
            {
                logger        = log4net.LogManager.GetLogger(categoryname).Logger;
                isInitialized = true;
                LogVelocityMessage(0, "SimpleLog4NetLogSystem using category '" + categoryname + "'");
                return;
            }

            // if not, use the file...
            String logfile = rsvc.getString(NVelocity.Runtime.RuntimeConstants_Fields.RUNTIME_LOG);

            // now init.  If we can't, panic!
            try {
                internalInit(logfile);

                LogVelocityMessage(0, "SimpleLog4NetLogSystem initialized using logfile '" + logfile + "'");
                isInitialized = true;

                foreach (LogMessage lm in cache)
                {
                    LogVelocityMessage(lm.Level, lm.Message);
                }
                cache = new ArrayList();
            } catch (System.Exception e) {
                System.Console.Out.WriteLine("PANIC : error configuring SimpleLog4NetLogSystem : " + e);
                isInitialized = false;
            }
        }