예제 #1
0
        /// <summary>控件绑定到日志,生成混合日志</summary>
        /// <param name="control"></param>
        /// <param name="log"></param>
        /// <param name="maxLines"></param>
        /// <returns></returns>
        public static ILog Combine(this Control control, ILog log, Int32 maxLines = 1000)
        {
            if (control == null || log == null)
            {
                return(log);
            }

            var clg = new TextControlLog
            {
                Control  = control,
                MaxLines = maxLines
            };

            return(new CompositeLog(log, clg));
        }
예제 #2
0
        /// <summary>在WinForm控件上输出日志,主要考虑非UI线程操作</summary>
        /// <remarks>不是常用功能,为了避免干扰常用功能,保持UseWinForm开头</remarks>
        /// <param name="control">要绑定日志输出的WinForm控件</param>
        /// <param name="useFileLog">是否同时使用文件日志,默认使用</param>
        /// <param name="maxLines">最大行数</param>
        public static void UseWinFormControl(this Control control, Boolean useFileLog = true, Int32 maxLines = 1000)
        {
            var clg = _Log as TextControlLog;
            var ftl = _Log as TextFileLog;

            if (_Log is CompositeLog cmp)
            {
                ftl = cmp.Get <TextFileLog>();
                clg = cmp.Get <TextControlLog>();
            }

            // 控制控制台日志
            if (clg == null)
            {
                clg = new TextControlLog();
            }
            clg.Control  = control;
            clg.MaxLines = maxLines;

            if (!useFileLog)
            {
                Log = clg;
                if (ftl != null)
                {
                    ftl.Dispose();
                }
            }
            else
            {
                if (ftl == null)
                {
                    ftl = TextFileLog.Create(null);
                }
                Log = new CompositeLog(clg, ftl);
            }
        }