mirror of
https://github.com/netchx/netch.git
synced 2026-03-18 18:13:21 +08:00
The Debug configuration will make the build attach to the console and write the application log to standard output
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
using Netch;
|
||||
|
||||
namespace UnitTest
|
||||
namespace UnitTest
|
||||
{
|
||||
public class TestBase
|
||||
{
|
||||
protected TestBase()
|
||||
{
|
||||
#if DEBUG
|
||||
Global.Testing = true;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user