From 6eb52341a7456f6fadd4eb854f9988ba310a59ea Mon Sep 17 00:00:00 2001 From: SpringHgui <740360381@qq.com> Date: Fri, 18 Jun 2021 23:40:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8log4net=E6=9B=BF=E6=8D=A2nlog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FastTunnel.Client/FastTunnel.Client.csproj | 7 +-- FastTunnel.Client/Program.cs | 32 ++-------- FastTunnel.Client/log4net.config | 72 ++++++++++++++++++++++ FastTunnel.Client/nlog.config | 26 -------- FastTunnel.Core/FastTunnel.Core.csproj | 2 - FastTunnel.Core/Logger/NlogConfig.cs | 34 ---------- FastTunnel.Server/FastTunnel.Server.csproj | 13 +--- FastTunnel.Server/Program.cs | 22 +------ FastTunnel.Server/config/appsettings.json | 2 +- FastTunnel.Server/log4net.config | 72 ++++++++++++++++++++++ FastTunnel.Server/nlog.config | 26 -------- 11 files changed, 156 insertions(+), 152 deletions(-) create mode 100644 FastTunnel.Client/log4net.config delete mode 100644 FastTunnel.Client/nlog.config delete mode 100644 FastTunnel.Core/Logger/NlogConfig.cs create mode 100644 FastTunnel.Server/log4net.config delete mode 100644 FastTunnel.Server/nlog.config diff --git a/FastTunnel.Client/FastTunnel.Client.csproj b/FastTunnel.Client/FastTunnel.Client.csproj index 908cb94..57fa4d8 100644 --- a/FastTunnel.Client/FastTunnel.Client.csproj +++ b/FastTunnel.Client/FastTunnel.Client.csproj @@ -13,8 +13,7 @@ - - + @@ -25,8 +24,8 @@ Always - - PreserveNewest + + Always diff --git a/FastTunnel.Client/Program.cs b/FastTunnel.Client/Program.cs index 1f79601..ee1f3f0 100644 --- a/FastTunnel.Client/Program.cs +++ b/FastTunnel.Client/Program.cs @@ -1,14 +1,5 @@ -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using System; -using System.IO; -using FastTunnel.Core.Services; -using Microsoft.Extensions.Hosting; -using FastTunnel.Core.Client; -using FastTunnel.Core.Config; -using FastTunnel.Core.Handlers.Client; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -using NLog.Web; using FastTunnel.Core.Extensions; namespace FastTunnel.Client @@ -17,22 +8,7 @@ namespace FastTunnel.Client { public static void Main(string[] args) { - var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger(); - try - { - CreateHostBuilder(args).Build().Run(); - } - catch (Exception exception) - { - //NLog: catch setup errors - logger.Error(exception, "Stopped program because of exception"); - throw; - } - finally - { - // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux) - NLog.LogManager.Shutdown(); - } + CreateHostBuilder(args).Build().Run(); } public static IHostBuilder CreateHostBuilder(string[] args) => @@ -47,7 +23,7 @@ namespace FastTunnel.Client { logging.ClearProviders(); logging.SetMinimumLevel(LogLevel.Trace); - }) - .UseNLog(); // NLog: Setup NLog for Dependency injection + logging.AddLog4Net(); + }); } } diff --git a/FastTunnel.Client/log4net.config b/FastTunnel.Client/log4net.config new file mode 100644 index 0000000..9fd5229 --- /dev/null +++ b/FastTunnel.Client/log4net.config @@ -0,0 +1,72 @@ + + + + + Value of priority may be ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FastTunnel.Client/nlog.config b/FastTunnel.Client/nlog.config deleted file mode 100644 index 53b543a..0000000 --- a/FastTunnel.Client/nlog.config +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/FastTunnel.Core/FastTunnel.Core.csproj b/FastTunnel.Core/FastTunnel.Core.csproj index 9f07668..efcce92 100644 --- a/FastTunnel.Core/FastTunnel.Core.csproj +++ b/FastTunnel.Core/FastTunnel.Core.csproj @@ -44,8 +44,6 @@ - - diff --git a/FastTunnel.Core/Logger/NlogConfig.cs b/FastTunnel.Core/Logger/NlogConfig.cs deleted file mode 100644 index a945d62..0000000 --- a/FastTunnel.Core/Logger/NlogConfig.cs +++ /dev/null @@ -1,34 +0,0 @@ -using NLog; -using NLog.Config; -using System; -using System.Collections.Generic; -using System.Text; - -namespace FastTunnel.Core.Logger -{ - public class NlogConfig - { - public static LoggingConfiguration getNewConfig() - { - var config = new LoggingConfiguration(); - - // Targets where to log to: File and Console - var logfile = new NLog.Targets.FileTarget("file") - { - FileName = "${basedir}/Logs/${shortdate}.${level}.log", - Layout = "${longdate} ${logger} ${message}${exception:format=ToString}" - }; - - var logconsole = new NLog.Targets.ConsoleTarget("console") - { - Layout = "${date}|${level:uppercase=true}|${message} ${exception} ${all-event-properties}" - }; - - // Rules for mapping loggers to targets - config.AddRule(LogLevel.Debug, LogLevel.Fatal, logconsole); - config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile); - - return config; - } - } -} diff --git a/FastTunnel.Server/FastTunnel.Server.csproj b/FastTunnel.Server/FastTunnel.Server.csproj index 71bcb70..25afaf4 100644 --- a/FastTunnel.Server/FastTunnel.Server.csproj +++ b/FastTunnel.Server/FastTunnel.Server.csproj @@ -6,21 +6,10 @@ true - - - - - - - PreserveNewest - - - - - + diff --git a/FastTunnel.Server/Program.cs b/FastTunnel.Server/Program.cs index f236317..ba7ea1b 100644 --- a/FastTunnel.Server/Program.cs +++ b/FastTunnel.Server/Program.cs @@ -5,7 +5,6 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -using NLog.Web; using System; namespace FastTunnel.Server @@ -14,22 +13,7 @@ namespace FastTunnel.Server { public static void Main(string[] args) { - var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger(); - try - { - CreateHostBuilder(args).Build().Run(); - } - catch (Exception exception) - { - //NLog: catch setup errors - logger.Error(exception, "Stopped program because of exception"); - throw; - } - finally - { - // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux) - NLog.LogManager.Shutdown(); - } + CreateHostBuilder(args).Build().Run(); } public static IHostBuilder CreateHostBuilder(string[] args) => @@ -58,7 +42,7 @@ namespace FastTunnel.Server { logging.ClearProviders(); logging.SetMinimumLevel(LogLevel.Trace); - }) - .UseNLog(); // NLog: Setup NLog for Dependency injection + logging.AddLog4Net(); + }); } } diff --git a/FastTunnel.Server/config/appsettings.json b/FastTunnel.Server/config/appsettings.json index b3bf791..7aa775a 100644 --- a/FastTunnel.Server/config/appsettings.json +++ b/FastTunnel.Server/config/appsettings.json @@ -15,7 +15,7 @@ "BindPort": 1271, // ×Ô¶¨ÒåÓòÃûweb´©Í¸±ØÐë - "WebDomain": "my.com", + "WebDomain": "test.cc", // ·þÎñ¼àÌýµÄ¶Ë¿ÚºÅ, ·ÃÎÊ×Ô¶¨ÒåÓòÃûÕ¾µãʱurlΪ http://{SubDomain}.{Domain}:{ProxyPort_HTTP}/ // web´©Í¸±ØÐë diff --git a/FastTunnel.Server/log4net.config b/FastTunnel.Server/log4net.config new file mode 100644 index 0000000..9fd5229 --- /dev/null +++ b/FastTunnel.Server/log4net.config @@ -0,0 +1,72 @@ + + + + + Value of priority may be ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FastTunnel.Server/nlog.config b/FastTunnel.Server/nlog.config deleted file mode 100644 index 53b543a..0000000 --- a/FastTunnel.Server/nlog.config +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file