/// <summary>使用控制台输出日志,只能调用一次</summary> /// <param name="useColor">是否使用颜色,默认使用</param> /// <param name="useFileLog">是否同时使用文件日志,默认使用</param> public static void UseConsole(Boolean useColor = true, Boolean useFileLog = true) { if (!Runtime.IsConsole) { return; } // 适当加大控制台窗口 try { if (Console.WindowWidth <= 80) { Console.WindowWidth = Console.WindowWidth * 3 / 2; } if (Console.WindowHeight <= 25) { Console.WindowHeight = Console.WindowHeight * 3 / 2; } } catch { } var clg = _Log as ConsoleLog; var ftl = _Log as TextFileLog; var cmp = _Log as CompositeLog; if (cmp != null) { ftl = cmp.Get <TextFileLog>(); clg = cmp.Get <ConsoleLog>(); } // 控制控制台日志 if (clg == null) { clg = new ConsoleLog { UseColor = useColor } } ; else { clg.UseColor = useColor; } if (!useFileLog) { // 如果原有提供者是文本日志,则直接替换 if (ftl != null) { Log = clg; ftl.Dispose(); } // 否则组件复合日志 else { if (cmp != null) { cmp.Remove(clg); if (cmp.Logs.Count == 0) { _Log = null; } } cmp = new CompositeLog(); cmp.Add(clg); if (_Log != null) { cmp.Add(_Log); } Log = cmp; } } else { cmp = new CompositeLog(); cmp.Add(clg); if (ftl == null) { //if (_Log != null) cmp.Add(_Log); ftl = TextFileLog.Create(null); } cmp.Add(ftl); Log = cmp; } //WriteVersion(); }