/// <summary> /// Initializes the logger, with alternate output handlers. /// </summary> /// <param name="verbosity"></param> /// <param name="write"></param> /// <param name="colorSet"></param> /// <param name="colorReset"></param> public SerialConsoleLogger ( LoggerVerbosity verbosity, WriteHandler write, ColorSetter colorSet, ColorResetter colorReset ) { InitializeConsoleMethods(verbosity, write, colorSet, colorReset); }
internal void InitializeConsoleMethods(LoggerVerbosity logverbosity, WriteHandler logwriter, ColorSetter colorSet, ColorResetter colorReset) { Verbosity = logverbosity; WriteHandler = logwriter; IsRunningWithCharacterFileType(); // This is a workaround, because the Console class provides no way to check that a color // can actually be set or not. Color cannot be set if the console has been redirected // in certain ways (e.g. how BUILD.EXE does it) bool canSetColor = true; try { ConsoleColor c = BackgroundColor; } catch (IOException) { // If the attempt to set a color fails with an IO exception then it is // likely that the console has been redirected in a way that cannot // cope with color (e.g. BUILD.EXE) so don't try to do color again. canSetColor = false; } if (colorSet != null && canSetColor) { this.setColor = colorSet; } else { this.setColor = DontSetColor; } if (colorReset != null && canSetColor) { this.resetColor = colorReset; } else { this.resetColor = DontResetColor; } }
internal void InitializeConsoleMethods(LoggerVerbosity logverbosity, WriteHandler logwriter, ColorSetter colorSet, ColorResetter colorReset) { this.verbosity = logverbosity; this.write = logwriter; IsRunningWithCharacterFileType(); // This is a workaround, because the Console class provides no way to check that a color // can actually be set or not. Color cannot be set if the console has been redirected // in certain ways (e.g. how BUILD.EXE does it) bool canSetColor = true; try { ConsoleColor c = Console.BackgroundColor; } catch (IOException) { // If the attempt to set a color fails with an IO exception then it is // likely that the console has been redirected in a way that cannot // cope with color (e.g. BUILD.EXE) so don't try to do color again. canSetColor = false; } if ((colorSet != null) && canSetColor) { this.setColor = colorSet; } else { this.setColor = new ColorSetter(DontSetColor); } if ((colorReset != null) && canSetColor) { this.resetColor = colorReset; } else { this.resetColor = new ColorResetter(DontResetColor); } }