diff --git a/v2rayN/v2rayN/App.xaml.cs b/v2rayN/v2rayN/App.xaml.cs index edba4acf..85eeed67 100644 --- a/v2rayN/v2rayN/App.xaml.cs +++ b/v2rayN/v2rayN/App.xaml.cs @@ -42,10 +42,11 @@ namespace v2rayN Global.processJob = new Job(); Logging.Setup(); + Init(); + Logging.LoggingEnabled(_config.guiItem.enableLog); Utils.SaveLog($"v2rayN start up | {Utils.GetVersion()} | {Utils.GetExePath()}"); Logging.ClearLogs(); - Init(); Thread.CurrentThread.CurrentUICulture = new(_config.uiItem.currentLanguage); diff --git a/v2rayN/v2rayN/Mode/ConfigItems.cs b/v2rayN/v2rayN/Mode/ConfigItems.cs index c204b425..5d81a24c 100644 --- a/v2rayN/v2rayN/Mode/ConfigItems.cs +++ b/v2rayN/v2rayN/Mode/ConfigItems.cs @@ -103,8 +103,10 @@ namespace v2rayN.Mode public bool enableSecurityProtocolTls13 { get; set; } public int trayMenuServersLimit { get; set; } = 20; - + public bool enableHWA { get; set; } = false; + + public bool enableLog { get; set; } = true; } [Serializable] diff --git a/v2rayN/v2rayN/Tool/Logging.cs b/v2rayN/v2rayN/Tool/Logging.cs index be43a2bb..e646ab3d 100644 --- a/v2rayN/v2rayN/Tool/Logging.cs +++ b/v2rayN/v2rayN/Tool/Logging.cs @@ -17,6 +17,13 @@ namespace v2rayN.Tool config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, fileTarget)); LogManager.Configuration = config; } + public static void LoggingEnabled(bool enable) + { + if (!enable) + { + LogManager.SuspendLogging(); + } + } public static void ClearLogs() { diff --git a/v2rayN/v2rayN/Tool/Utils.cs b/v2rayN/v2rayN/Tool/Utils.cs index 76465b86..b3c97c45 100644 --- a/v2rayN/v2rayN/Tool/Utils.cs +++ b/v2rayN/v2rayN/Tool/Utils.cs @@ -780,7 +780,7 @@ namespace v2rayN task.Settings.RunOnlyIfIdle = false; task.Settings.IdleSettings.StopOnIdleEnd = false; task.Settings.ExecutionTimeLimit = TimeSpan.Zero; - task.Triggers.Add(new LogonTrigger { UserId = logonUser, Delay = TimeSpan.FromMinutes(1) }); + task.Triggers.Add(new LogonTrigger { UserId = logonUser, Delay = TimeSpan.FromSeconds(10) }); task.Principal.RunLevel = TaskRunLevel.Highest; task.Actions.Add(new ExecAction(deamonFileName)); @@ -1152,17 +1152,23 @@ namespace v2rayN public static void SaveLog(string strContent) { - var logger = LogManager.GetLogger("Log1"); - logger.Info(strContent); + if (LogManager.IsLoggingEnabled()) + { + var logger = LogManager.GetLogger("Log1"); + logger.Info(strContent); + } } public static void SaveLog(string strTitle, Exception ex) { - var logger = LogManager.GetLogger("Log2"); - logger.Debug($"{strTitle},{ex.Message}"); - logger.Debug(ex.StackTrace); - if (ex?.InnerException != null) + if (LogManager.IsLoggingEnabled()) { - logger.Error(ex.InnerException); + var logger = LogManager.GetLogger("Log2"); + logger.Debug($"{strTitle},{ex.Message}"); + logger.Debug(ex.StackTrace); + if (ex?.InnerException != null) + { + logger.Error(ex.InnerException); + } } }