The Debug configuration will make the build attach to the console and write the application log to standard output

This commit is contained in:
ChsBuffer
2021-03-19 00:58:34 +08:00
parent 6178045f15
commit cfb4a5b3f6
5 changed files with 16 additions and 26 deletions

View File

@@ -34,12 +34,6 @@ namespace Netch
public static Mutex Mutex => LazyMutex.Value;
#if DEBUG
public static bool Testing = false;
#else
public const bool Testing = false;
#endif
/// <summary>
/// 用于读取和写入的配置
/// </summary>

View File

@@ -22,9 +22,12 @@ namespace Netch
[STAThread]
public static void Main(string[] args)
{
#if DEBUG
AttachConsole();
#else
if (args.Contains("-console"))
if (!NativeMethods.AttachConsole(-1))
NativeMethods.AllocConsole();
AttachConsole();
#endif
// 设置当前目录
Directory.SetCurrentDirectory(Global.NetchDir);
@@ -85,6 +88,12 @@ namespace Netch
Application.Run(Global.MainForm);
}
private static void AttachConsole()
{
if (!NativeMethods.AttachConsole(-1))
NativeMethods.AllocConsole();
}
public static void Application_OnException(object sender, ThreadExceptionEventArgs e)
{
Logging.Error(e.Exception.ToString());

View File

@@ -40,14 +40,12 @@ namespace Netch.Utils
private static void Write(string text, LogLevel logLevel)
{
var contents = $@"[{DateTime.Now}][{logLevel.ToString()}] {text}{Global.EOF}";
if (Global.Testing)
{
Console.WriteLine(contents);
return;
}
#if DEBUG
Console.WriteLine(contents);
#else
lock (FileLock)
File.AppendAllText(LogFile, contents);
#endif
}
}
}

View File

@@ -21,8 +21,6 @@ namespace Netch.Utils
{
public static bool Open(string path)
{
if (Global.Testing)
return true;
try
{
Process.Start(new ProcessStartInfo
@@ -139,7 +137,6 @@ namespace Netch.Utils
return File.Exists(file) ? FileVersionInfo.GetVersionInfo(file).FileVersion : string.Empty;
}
public static void DrawCenterComboBox(object sender, DrawItemEventArgs e)
{
if (sender is ComboBox cbx)

View File

@@ -1,14 +1,6 @@
using Netch;
namespace UnitTest
namespace UnitTest
{
public class TestBase
{
protected TestBase()
{
#if DEBUG
Global.Testing = true;
#endif
}
}
}