@staticmethod<EOL><INDENT>def Write(log: Any, consoleColor: int = ConsoleColor.Default, writeToFile: bool = True, printToStdout: bool = True, logFile: str = None, printTruncateLen: int = <NUM_LIT:0>) -> None:<DEDENT>
if not isinstance(log, str):<EOL><INDENT>log = str(log)<EOL><DEDENT>if printToStdout and sys.stdout:<EOL><INDENT>isValidColor = (consoleColor >= ConsoleColor.Black and consoleColor <= ConsoleColor.White)<EOL>if isValidColor:<EOL><INDENT>SetConsoleColor(consoleColor)<EOL><DEDENT>try:<EOL><INDENT>if printTruncateLen > <NUM_LIT:0> and len(log) > printTruncateLen:<EOL><INDENT>sys.stdout.write(log[:printTruncateLen] + '<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>sys.stdout.write(log)<EOL><DEDENT><DEDENT>except Exception as ex:<EOL><INDENT>SetConsoleColor(ConsoleColor.Red)<EOL>isValidColor = True<EOL>sys.stdout.write(ex.__class__.__name__ + '<STR_LIT>')<EOL>if log.endswith('<STR_LIT:\n>'):<EOL><INDENT>sys.stdout.write('<STR_LIT:\n>')<EOL><DEDENT><DEDENT>if isValidColor:<EOL><INDENT>ResetConsoleColor()<EOL><DEDENT>sys.stdout.flush()<EOL><DEDENT>if not writeToFile:<EOL><INDENT>return<EOL><DEDENT>fileName = logFile if logFile else Logger.FileName<EOL>try:<EOL><INDENT>fout = open(fileName, '<STR_LIT>', encoding='<STR_LIT:utf-8>')<EOL>fout.write(log)<EOL><DEDENT>except Exception as ex:<EOL><INDENT>if sys.stdout:<EOL><INDENT>sys.stdout.write(ex.__class__.__name__ + '<STR_LIT>')<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>if fout:<EOL><INDENT>fout.close()<EOL><DEDENT><DEDENT>
log: any type.
consoleColor: int, a value in class `ConsoleColor`, such as `ConsoleColor.DarkGreen`.
writeToFile: bool.
printToStdout: bool.
logFile: str, log file path.
printTruncateLen: int, if <= 0, log is not truncated when print.