Exemplo n.º 1
0
        private void ProcessLoop()
        {
            TimeSpan waitForExitTimeSpan = new TimeSpan(0);

            while (true)
            {
                try
                {
                    LogMessage log = LogManagement.Instance().GetLog(new TimeSpan(0, 0, 0, 0, this.milliSecondsToGetLog));

                    if (log != null)
                    {
                        Logger          logger      = log.LogActor;
                        ILogDistination distination = LogManagement.Instance().GetDistination(logger.Config);

                        distination.Write(log);

                        // to write all log
                        continue;
                    }
                }
                // just catch timeout exception, if timeout, do nothing.
                catch (TimeoutException)
                {
                }

                // thread need to exit
                if (this.exitEvent.WaitOne(waitForExitTimeSpan, false))
                {
                    break;
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// The only instance of LogManagement
 /// </summary>
 /// <returns></returns>
 public static LogManagement Instance()
 {
     if (instance == null)
     {
         instance = new LogManagement();
     }
     return(instance);
 }
Exemplo n.º 3
0
        private void WriteMessage(string logMsg, LogLevel level)
        {
            LogLevel configLevel = this.Config.Level;

            if (configLevel < level)
            {
                LogMessage log = new LogMessage(this, logMsg, level);
                LogManagement.Instance().AddLog(log);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// create LogConfig instance
        /// </summary>
        /// <param name="fileName">the xml config file name</param>
        /// <param name="configId">the config id</param>
        /// <returns>the logconfig instance</returns>
        public LogConfig(string fileName, string configId)
        {
            LogManagement.Instance().Initialize(fileName);
            LogConfigBase config = LogManagement.Instance().Site.Config.LogConfigs[configId];

            if (config == null)
            {
                throw new StackException(string.Format(CultureInfo.InvariantCulture, "the config can not be found, id={0}", configId));
            }

            this.realLogConfig = config;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Constructor
        /// </summary>
        public LogThread()
        {
            this.exitEvent = new ManualResetEvent(false);

            this.milliSecondsToGetLog = 100;
            if (LogManagement.Instance().Site != null)
            {
                this.milliSecondsToGetLog = LogManagement.Instance().Site.Config.MilliSecondsToGetLog;
            }

            this.logProcThread      = new Thread(ProcessLoop);
            this.logProcThread.Name = "log proc thread";
            this.logProcThread.Start();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Release all resources
        /// </summary>
        /// <param name="disposing">Indicates user or GC calling this function</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    //Release managed resource.
                    LogManagement.Instance().RemoveLogger(this);
                    if (LogManagement.Instance().LoggerCount == 0)
                    {
                        //LogManagement.Finalize();
                    }
                }

                //Note disposing has been done.
                this.disposed = true;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="logConfig">The log config</param>
        public Logger(LogConfig logConfig)
        {
            this.Config = logConfig.RealLogConfig;

            LogManagement.Instance().AddLogger(this);
        }