Пример #1
0
 public AsyncLogWriter(string name, string path, QueueTask <AsyncItem> asyncQueue)
     : base(name, path)
 {
     this.asyncQueue = asyncQueue;
 }
Пример #2
0
        /// <summary>
        /// 初始化新实例并指定名称
        /// </summary>
        /// <param name="name">日志组名称</param>
        /// <param name="path">当为Null时,若配置(AppSetting)Log:Path则为配置值,否则以当前应用程序目录下Log为目录</param>
        public LogManager(string name, string path)
        {
            this.Name     = name ?? string.Empty;
            this.IsOwnner = !string.Empty.Equals(this.Name);
            //
            if (string.IsNullOrEmpty(path))
            {
                path = GetConfig("Log:Path");
                if (string.Empty.Equals(path))
                {
                    path = System.IO.Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "Log");
                }
            }
            this.path = path;
            //
            this.asyncQueue = new QueueTask <AsyncItem>(this.AsyncLogFlush);
            //
            var logDisabled = GetConfig("Log:Disabled") ?? "";

            this.AllDisabled = "all".Equals(logDisabled, StringComparison.OrdinalIgnoreCase);
            //
            if (this.IsOwnner)
            {
                this.Message = new ManageLogWriter(name, path);
                this.Warning = new ManageLogWriter(string.Concat(name, "-warning"), path);
                this.Error   = new ManageLogWriter(string.Concat(name, "-error"), path);
                this.Debug   = new ManageLogWriter(string.Concat(name, "-debug"), path);
            }
            else
            {
                this.Message = new ManageLogWriter("message", path);
                this.Warning = new ManageLogWriter("warning", path);
                this.Error   = new ManageLogWriter("error", path);
                this.Debug   = new ManageLogWriter("debug", path);
            }

            //set manage
            this.Message.Manager = this;
            this.Warning.Manager = this;
            this.Error.Manager   = this;
            this.Debug.Manager   = this;
            //set level
            this.Message.Level = LogLevel.Message;
            this.Warning.Level = LogLevel.Warning;
            this.Error.Level   = LogLevel.Error;
            this.Debug.Level   = LogLevel.Debug;
            //enable
            this.Message.Enable = this.GetDisable(this.Message, "Message");
            this.Warning.Enable = this.GetDisable(this.Warning, "Warning");
            this.Error.Enable   = this.GetDisable(this.Error, "Error");
            this.Debug.Enable   = this.GetDisable(this.Debug, "Debug");
            //writing
            this.Message.Writing += this.WritingEvent;
            this.Warning.Writing += this.WritingEvent;
            this.Error.Writing   += this.WritingEvent;
            //console
            this.Warning.ConsoleColor = ConsoleColor.Yellow;
            this.Error.ConsoleColor   = ConsoleColor.Red;
            //
            this.writers.Add(this.Message.Name, this.Message);
            this.writers.Add(this.Warning.Name, this.Warning);
            this.writers.Add(this.Error.Name, this.Error);
            //
            this.NewExceptionToMail = ExceptionMail.Instance.Available;
            //
            this.intervalLoop.Arrived += this.Arrived;
            //
            var interval = GetConfigAsInt("Log:FlushInterval", 0);

            this.SetFlushInterval(interval);
            //
            Adf.Config.LogConfig.Instance.Changed += this.ConfigChanged;
        }