C# Jenkins控制台输出显示额外信息
我正在使用Jenkins来启动和监控我们的自动回归测试工具。工具本身将使用C#和Console.WriteLine()显示信息;这在屏幕上运行良好C# Jenkins控制台输出显示额外信息,c#,jenkins,console,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
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_uu为false,因此此函数不会更改控制台颜色
有趣的是,该程序的初始启动将显示控制台输出,这并不存在字体捕获问题
string[] AboutText = {
"TestTool.exe - " + CSharpUtilities.ConsoleUtilities.ApplicationVersion,
"Copyright (c) 2014",
""
};
ConsoleUtilities.ShowText(AboutText, LogPathFileName);
此代码在日志上生成信息,而不捕获字体信息
TestTool.exe - 1.1.5976.16032
Copyright (c) 2014
在第一次测试之前,这会被打印到日志中,不会出现任何问题。如果您注释掉该日志行,字体信息是否仍然会出现问题?i、 可能是您的组件中的其他代码或您正在使用的库也在编写日志吗?@Rup i对日志进行了注释,没有任何更改。我已经用完整的课程更新了这个问题。有趣的是,初始程序转储没有问题,但部分行转储有问题。如果您注释掉该日志行,字体信息是否仍然会被提升?i、 可能是您的组件中的其他代码或您正在使用的库也在编写日志吗?@Rup i对日志进行了注释,没有任何更改。我已经用完整的课程更新了这个问题。有趣的是,初始程序转储没有问题,但部分行转储有问题。