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; } } }
/// <summary> /// The only instance of LogManagement /// </summary> /// <returns></returns> public static LogManagement Instance() { if (instance == null) { instance = new LogManagement(); } return(instance); }
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); } }
/// <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; }
/// <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(); }
/// <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; } }
/// <summary> /// Constructor /// </summary> /// <param name="logConfig">The log config</param> public Logger(LogConfig logConfig) { this.Config = logConfig.RealLogConfig; LogManagement.Instance().AddLogger(this); }