From ee206f3df0ae576c4f52e5844871065140a07394 Mon Sep 17 00:00:00 2001 From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com> Date: Thu, 15 Jul 2021 14:29:56 +0800 Subject: [PATCH] Update Log --- Netch/Controllers/MainController.cs | 17 ++++++++++------- Netch/Controllers/TUNController.cs | 1 - Netch/Interops/AioDNS.cs | 2 +- Netch/Interops/Redirector.cs | 2 +- Netch/Interops/tun2socks.cs | 4 ++-- Netch/Netch.cs | 2 ++ Netch/Utils/PortHelper.cs | 6 ++++-- Netch/Utils/RouteUtils.cs | 18 +++++++++++++++++- 8 files changed, 37 insertions(+), 15 deletions(-) diff --git a/Netch/Controllers/MainController.cs b/Netch/Controllers/MainController.cs index 2b960552..b0749e8b 100644 --- a/Netch/Controllers/MainController.cs +++ b/Netch/Controllers/MainController.cs @@ -35,10 +35,11 @@ namespace Netch.Controllers if (Log.IsEnabled(LogEventLevel.Debug)) Task.Run(() => - { - // TODO log level setting - Log.Debug("Running Processes: \n{Processes}", string.Join("\n", SystemInfo.Processes(false))); - }).Forget(); + { + // TODO log level setting + Log.Debug("Running Processes: \n{Processes}", string.Join("\n", SystemInfo.Processes(false))); + }) + .Forget(); try { @@ -73,7 +74,7 @@ namespace Netch.Controllers Global.MainForm.StatusText(i18N.TranslateFormat("Starting {0}", ServerController.Name)); - Log.Debug($"{server.Type} {server.MaskedData()}"); + Log.Debug("Server Information: {Data}", $"{server.Type} {server.MaskedData()}"); var socks5 = ServerController.Start(server); StatusPortInfoText.Socks5Port = socks5.Port; @@ -134,7 +135,8 @@ namespace Netch.Controllers } catch (PortReservedException) { - throw new MessageException(i18N.TranslateFormat("The {0} port is reserved by system.", $"{portName} ({port})")); + throw new MessageException(i18N.TranslateFormat("The {0} port is reserved by system.", + $"{portName} ({port})")); } } @@ -153,7 +155,8 @@ namespace Netch.Controllers } else { - throw new MessageException(i18N.TranslateFormat("The {0} port is used by {1}.", $"{portName} ({port})", $"({p.Id}){fileName}")); + throw new MessageException(i18N.TranslateFormat("The {0} port is used by {1}.", + $"{portName} ({port})", $"({p.Id}){fileName}")); } } diff --git a/Netch/Controllers/TUNController.cs b/Netch/Controllers/TUNController.cs index 18840577..fe0afb4a 100644 --- a/Netch/Controllers/TUNController.cs +++ b/Netch/Controllers/TUNController.cs @@ -147,7 +147,6 @@ namespace Netch.Controllers private void SetupRouteTable() { Global.MainForm.StatusText(i18N.Translate("Setup Route Table Rule")); - Log.Information("设置路由规则"); // Server Address if (_serverRemoteAddress != null) diff --git a/Netch/Interops/AioDNS.cs b/Netch/Interops/AioDNS.cs index 108d35da..1d5624ac 100644 --- a/Netch/Interops/AioDNS.cs +++ b/Netch/Interops/AioDNS.cs @@ -10,7 +10,7 @@ namespace Netch.Interops public static bool Dial(NameList name, string value) { - Log.Debug($"[aiodns] Dial {name}: {value}"); + Log.Verbose($"[aiodns] Dial {name}: {value}"); return aiodns_dial(name, Encoding.UTF8.GetBytes(value)); } diff --git a/Netch/Interops/Redirector.cs b/Netch/Interops/Redirector.cs index ddbc7f8e..db15047a 100644 --- a/Netch/Interops/Redirector.cs +++ b/Netch/Interops/Redirector.cs @@ -43,7 +43,7 @@ namespace Netch.Interops public static bool Dial(NameList name, string value) { - Log.Debug($"[Redirector] Dial {name}: {value}"); + Log.Verbose($"[Redirector] Dial {name}: {value}"); return aio_dial(name, value); } diff --git a/Netch/Interops/tun2socks.cs b/Netch/Interops/tun2socks.cs index d4b61dcd..8280cda8 100644 --- a/Netch/Interops/tun2socks.cs +++ b/Netch/Interops/tun2socks.cs @@ -36,13 +36,13 @@ namespace Netch.Interops public static bool Dial(NameList name, string value) { - Log.Debug( $"[tun2socks] Dial {name}: {value}"); + Log.Verbose( $"[tun2socks] Dial {name}: {value}"); return tun_dial(name, Encoding.UTF8.GetBytes(value)); } public static bool Init() { - Log.Debug("[tun2socks] init"); + Log.Verbose("[tun2socks] init"); return tun_init(); } diff --git a/Netch/Netch.cs b/Netch/Netch.cs index e11bae53..aa2dd44b 100644 --- a/Netch/Netch.cs +++ b/Netch/Netch.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Threading; @@ -99,6 +100,7 @@ namespace Netch Log.Information("Netch Version: {Version}", $"{UpdateChecker.Owner}/{UpdateChecker.Repo}@{UpdateChecker.Version}"); Log.Information("Environment: {OSVersion}", Environment.OSVersion); Log.Information("SHA256: {Hash}", $"{Utils.Utils.SHA256CheckSum(Global.NetchExecutable)}"); + Log.Information("System Language: {Language}", CultureInfo.CurrentCulture.Name); if (Log.IsEnabled(LogEventLevel.Debug)) Log.Debug("Third-party Drivers:\n{Drivers}", string.Join("\n", SystemInfo.SystemDrivers(false))); } diff --git a/Netch/Utils/PortHelper.cs b/Netch/Utils/PortHelper.cs index 13dd0749..bfb021ae 100644 --- a/Netch/Utils/PortHelper.cs +++ b/Netch/Utils/PortHelper.cs @@ -135,7 +135,8 @@ namespace Netch.Utils break; default: - throw new ArgumentOutOfRangeException(nameof(type), type, null); + Trace.Assert(false); + return; } } @@ -161,7 +162,8 @@ namespace Netch.Utils break; default: - throw new ArgumentOutOfRangeException(nameof(type), type, null); + Trace.Assert(false); + return; } } diff --git a/Netch/Utils/RouteUtils.cs b/Netch/Utils/RouteUtils.cs index 8bfb9485..26260242 100644 --- a/Netch/Utils/RouteUtils.cs +++ b/Netch/Utils/RouteUtils.cs @@ -28,6 +28,14 @@ namespace Netch.Utils public static bool CreateRoute(NetRoute o) { + Log.Verbose("CreateRoute {InterNetwork} {Address} {Cidr} {Gateway} {Interface} {Metric}", + AddressFamily.InterNetwork, + o.Network, + o.Cidr, + o.Gateway, + (ulong)o.InterfaceIndex, + o.Metric); + return RouteHelper.CreateRoute(AddressFamily.InterNetwork, o.Network, o.Cidr, o.Gateway, (ulong)o.InterfaceIndex, o.Metric); } @@ -41,7 +49,7 @@ namespace Netch.Utils { if (!TryParseIPNetwork(rule, out var network, out var cidr)) { - Log.Warning("invalid rule {Rule}",rule); + Log.Warning("invalid rule {Rule}", rule); return false; } @@ -50,6 +58,14 @@ namespace Netch.Utils public static bool DeleteRoute(NetRoute o) { + Log.Verbose("DeleteRoute {InterNetwork} {Address} {Cidr} {Gateway} {Interface} {Metric}", + AddressFamily.InterNetwork, + o.Network, + o.Cidr, + o.Gateway, + (ulong)o.InterfaceIndex, + o.Metric); + return RouteHelper.DeleteRoute(AddressFamily.InterNetwork, o.Network, o.Cidr, o.Gateway, (ulong)o.InterfaceIndex, o.Metric); }