Jenkins控制台输出显示额外信息

时间:2016-05-12 13:35:19

标签: c# jenkins console

我正在使用Jenkins启动和监控我们的自动回归测试工具。该工具本身将使用C#和Console.WriteLine()显示信息;这在屏幕上工作正常。

TestTool.exe - 1.1.5976.16032
Copyright (c) 2014

REPLAY   1 of 197 20160511_1904-50\mantis6937_005             OK
REPLAY   2 of 197 20160511_1904-50\mantis6937_004             OK

但是,当我查看Jenkins控制台日志中的信息时,它似乎捕获了一些字体信息?

REPLAY   1 of 197 20160511_1904-50\mantis6937_005                  Black
Bold
Book
Condensed
Demi-Bold
East
...
Upside-Down
West
    OK
REPLAY   2 of 197 20160511_1904-50\mantis6937_004                  Black
Bold
Book
Condensed
Demi-Bold
East
...
Upside-Down
West
    OK

C#代码静态类

    public class ConsoleUtilities
    {
        public const int FILE_NAME_SPACING = 35;
        public const int STATUS_SPACING = 10;

        private static bool UseColor_ = true;
        public static bool UseColor
        {
            get {   return UseColor_; }
            set {   UseColor_ = value;  }
        }

        public static string ApplicationVersion
        {
            get {
                Assembly MyProgram = Assembly.GetEntryAssembly();
                return MyProgram.GetName().Version.ToString();
            }
        }

        public static void ShowText(string[] HelpText, string LogPathFileName) {
            foreach (string HelpLine in HelpText) {
                ShowText(HelpLine, System.ConsoleColor.Gray, System.ConsoleColor.Black, LogPathFileName);
            }
        }

        public static void ShowText(string HelpLine, System.ConsoleColor Foreground, System.ConsoleColor Background, string LogPathFileName) {
            ShowTextOnConsole(HelpLine, Foreground, Background, true, LogPathFileName);
        }

        public static void ShowText(string HelpLine, string LogPathFileName) {
            ShowTextOnConsole(HelpLine, System.ConsoleColor.Gray, System.ConsoleColor.Black, true, LogPathFileName);
        }

        public static void ShowPartialText(string Text, string LogPathFileName) {
            ShowTextOnConsole(Text, System.ConsoleColor.Gray, System.ConsoleColor.Black, false, LogPathFileName);
        }

        public static void ShowPartialText(string Text, System.ConsoleColor Foreground, System.ConsoleColor Background, string LogPathFileName) {
            ShowTextOnConsole(Text, Foreground, Background, false, LogPathFileName);
        }

        private static void LogText(string LogPathAndFileName, string Text, bool AddNewLine) {
            using (System.IO.StreamWriter Output = new System.IO.StreamWriter(LogPathAndFileName, true)) {
                if (AddNewLine) {
                    Output.WriteLine(Text);
                } else {
                    Output.Write(Text);
                }
            }
        }

        private static void ShowTextOnConsole(string Text, System.ConsoleColor Foreground, System.ConsoleColor Background, bool AddNewLine, string LogPathFileName) {
            if (UseColor_) {
                Console.ForegroundColor = Foreground;
                Console.BackgroundColor = Background;
            }
            if (AddNewLine) {
                Console.WriteLine(Text);
            } else {
                Console.Write(Text);
            }
            if (UseColor_) {
                Console.ResetColor();
            }
            if (LogPathFileName != "") {
                LogText(LogPathFileName, Text, AddNewLine);
            }
        }

        public static string FormatFileDisplayStatus(string FileName, string Status) {
            return FormatFileDisplayStatus(FileName, Status, FILE_NAME_SPACING, STATUS_SPACING);
        }

        public static string FormatFileDisplayStatus(string FileName, string Status, int FileNameWidth) {
            return FormatFileDisplayStatus(FileName, Status, FileNameWidth, STATUS_SPACING);
        }

        public static string FormatFileDisplayStatus(string FileName, string Status, int FileNameWidth, int StatusWidth) {
            string FormatedText = "".PadRight(2) + FileName.PadRight(FileNameWidth) + " - " + Status.PadRight(StatusWidth);
            return FormatedText;
        }

        ~ConsoleUtilities()
        {
        }
     }
}

此示例中的内部UseColor_为false,因此此功能不会更改控制台颜色。

有趣的是程序的初始启动会显示控制台输出,但没有字体捕获问题。

string[] AboutText = { 
    "TestTool.exe - " + CSharpUtilities.ConsoleUtilities.ApplicationVersion,
    "Copyright (c) 2014",
    ""
};
ConsoleUtilities.ShowText(AboutText, LogPathFileName);

此代码生成有关日志的信息,但不捕获字体信息。

TestTool.exe - 1.1.5976.16032
Copyright (c) 2014

在第一次测试之前将其打印到日志中,也没有任何问题。

0 个答案:

没有答案