From fa12071d6d6798955a19542242affd200b86f1ea Mon Sep 17 00:00:00 2001
From: SpringHgui <740360381@qq.com>
Date: Thu, 9 Apr 2020 10:34:59 +0800
Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=8F=98nlog=E9=85=8D=E7=BD=AE?=
=?UTF-8?q?=E7=9A=84=E6=96=B9=E5=BC=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
FastTunnel.Client/FastTunnel.Client.csproj | 3 ---
FastTunnel.Client/Nlog.config | 17 --------------
FastTunnel.Client/Program.cs | 3 ++-
FastTunnel.Core/FastTunnel.Core.csproj | 6 -----
FastTunnel.Core/Logger/NlogConfig.cs | 26 ++++++++++++++++++++++
FastTunnel.Server/FastTunnel.Server.csproj | 3 ---
FastTunnel.Server/Nlog.config | 18 ---------------
FastTunnel.Server/Program.cs | 3 ++-
SuiDao.Client/Nlog.config | 17 --------------
SuiDao.Client/Program.cs | 6 +++--
SuiDao.Client/SuiDao.Client.csproj | 6 -----
SuiDao.Client/nuget.config | 2 +-
SuiDao.Server/Nlog.config | 17 --------------
SuiDao.Server/Program.cs | 3 ++-
SuiDao.Server/SuiDao.Server.csproj | 3 ---
publish.cmd | 2 +-
16 files changed, 38 insertions(+), 97 deletions(-)
delete mode 100644 FastTunnel.Client/Nlog.config
create mode 100644 FastTunnel.Core/Logger/NlogConfig.cs
delete mode 100644 FastTunnel.Server/Nlog.config
delete mode 100644 SuiDao.Client/Nlog.config
delete mode 100644 SuiDao.Server/Nlog.config
diff --git a/FastTunnel.Client/FastTunnel.Client.csproj b/FastTunnel.Client/FastTunnel.Client.csproj
index 402fc6a..f6c5348 100644
--- a/FastTunnel.Client/FastTunnel.Client.csproj
+++ b/FastTunnel.Client/FastTunnel.Client.csproj
@@ -26,9 +26,6 @@
Always
-
- Always
-
diff --git a/FastTunnel.Client/Nlog.config b/FastTunnel.Client/Nlog.config
deleted file mode 100644
index bf183f2..0000000
--- a/FastTunnel.Client/Nlog.config
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/FastTunnel.Client/Program.cs b/FastTunnel.Client/Program.cs
index 859caea..26803a5 100644
--- a/FastTunnel.Client/Program.cs
+++ b/FastTunnel.Client/Program.cs
@@ -14,6 +14,7 @@ using FastTunnel.Core.Config;
using FastTunnel.Core.Core;
using FastTunnel.Core.Models;
using FastTunnel.Core.Handlers.Client;
+using FastTunnel.Core.Logger;
namespace FastTunnel.Client
{
@@ -21,7 +22,7 @@ namespace FastTunnel.Client
{
static void Main(string[] args)
{
- LogManager.LoadConfiguration("Nlog.config");
+ LogManager.Configuration = NlogConfig.getNewConfig();
var logger = LogManager.GetCurrentClassLogger();
logger.Debug("===== FastTunnel Client Start =====");
diff --git a/FastTunnel.Core/FastTunnel.Core.csproj b/FastTunnel.Core/FastTunnel.Core.csproj
index 7feb12a..c6d158d 100644
--- a/FastTunnel.Core/FastTunnel.Core.csproj
+++ b/FastTunnel.Core/FastTunnel.Core.csproj
@@ -7,12 +7,6 @@
-
-
-
-
-
-
diff --git a/FastTunnel.Core/Logger/NlogConfig.cs b/FastTunnel.Core/Logger/NlogConfig.cs
new file mode 100644
index 0000000..aae4383
--- /dev/null
+++ b/FastTunnel.Core/Logger/NlogConfig.cs
@@ -0,0 +1,26 @@
+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 fff88ac..e3fe126 100644
--- a/FastTunnel.Server/FastTunnel.Server.csproj
+++ b/FastTunnel.Server/FastTunnel.Server.csproj
@@ -28,9 +28,6 @@
Always
-
- Always
-
diff --git a/FastTunnel.Server/Nlog.config b/FastTunnel.Server/Nlog.config
deleted file mode 100644
index 82d4f89..0000000
--- a/FastTunnel.Server/Nlog.config
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/FastTunnel.Server/Program.cs b/FastTunnel.Server/Program.cs
index 84102b3..2bb2222 100644
--- a/FastTunnel.Server/Program.cs
+++ b/FastTunnel.Server/Program.cs
@@ -18,6 +18,7 @@ using FastTunnel.Core.Host;
using FastTunnel.Core.Core;
using FastTunnel.Core.Handlers;
using FastTunnel.Core.Handlers.Server;
+using FastTunnel.Core.Logger;
namespace FastTunnel.Server
{
@@ -27,7 +28,7 @@ namespace FastTunnel.Server
static void Main(string[] args)
{
- LogManager.LoadConfiguration("Nlog.config");
+ LogManager.Configuration = NlogConfig.getNewConfig();
var logger = LogManager.GetCurrentClassLogger();
logger.Debug("===== FastTunnel Server Start =====");
diff --git a/SuiDao.Client/Nlog.config b/SuiDao.Client/Nlog.config
deleted file mode 100644
index bf183f2..0000000
--- a/SuiDao.Client/Nlog.config
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/SuiDao.Client/Program.cs b/SuiDao.Client/Program.cs
index 16b2597..382fceb 100644
--- a/SuiDao.Client/Program.cs
+++ b/SuiDao.Client/Program.cs
@@ -3,11 +3,13 @@ using FastTunnel.Core.Config;
using FastTunnel.Core.Core;
using FastTunnel.Core.Handlers.Client;
using FastTunnel.Core.Host;
+using FastTunnel.Core.Logger;
using FastTunnel.Core.Models;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NLog;
+using NLog.Extensions.Logging;
using SuiDao.Client.Models;
using System;
using System.Collections.Generic;
@@ -29,9 +31,9 @@ namespace SuiDao.Client
///
static void Main(string[] args)
{
- LogManager.LoadConfiguration("Nlog.config");
+ LogManager.Configuration = NlogConfig.getNewConfig();
var logger = LogManager.GetCurrentClassLogger();
- logger.Debug("===== SuiDao Client Start =====");
+ logger.Info("===== SuiDao Client Start =====");
var keyFile = Path.Combine(AppContext.BaseDirectory, KeyLogName);
if (!File.Exists(keyFile))
diff --git a/SuiDao.Client/SuiDao.Client.csproj b/SuiDao.Client/SuiDao.Client.csproj
index 0998808..ad082fc 100644
--- a/SuiDao.Client/SuiDao.Client.csproj
+++ b/SuiDao.Client/SuiDao.Client.csproj
@@ -14,10 +14,4 @@
-
-
- Always
-
-
-
diff --git a/SuiDao.Client/nuget.config b/SuiDao.Client/nuget.config
index dab3073..f7fd5ee 100644
--- a/SuiDao.Client/nuget.config
+++ b/SuiDao.Client/nuget.config
@@ -3,7 +3,7 @@
-
+
diff --git a/SuiDao.Server/Nlog.config b/SuiDao.Server/Nlog.config
deleted file mode 100644
index bf183f2..0000000
--- a/SuiDao.Server/Nlog.config
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/SuiDao.Server/Program.cs b/SuiDao.Server/Program.cs
index c998321..a9ce273 100644
--- a/SuiDao.Server/Program.cs
+++ b/SuiDao.Server/Program.cs
@@ -3,6 +3,7 @@ using FastTunnel.Core.Core;
using FastTunnel.Core.Handlers;
using FastTunnel.Core.Handlers.Server;
using FastTunnel.Core.Host;
+using FastTunnel.Core.Logger;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NLog;
@@ -18,7 +19,7 @@ namespace SuiDao.Server
static void Main(string[] args)
{
- LogManager.LoadConfiguration("Nlog.config");
+ LogManager.Configuration = NlogConfig.getNewConfig();
var logger = LogManager.GetCurrentClassLogger();
logger.Debug("===== FastTunnel Server Start =====");
diff --git a/SuiDao.Server/SuiDao.Server.csproj b/SuiDao.Server/SuiDao.Server.csproj
index 2b07bf9..eb0647c 100644
--- a/SuiDao.Server/SuiDao.Server.csproj
+++ b/SuiDao.Server/SuiDao.Server.csproj
@@ -19,9 +19,6 @@
Always
-
- Always
-
diff --git a/publish.cmd b/publish.cmd
index 9dbc6de..c847cd8 100644
--- a/publish.cmd
+++ b/publish.cmd
@@ -3,7 +3,7 @@
for /d %%p in (FastTunnel.Client,FastTunnel.Server,SuiDao.Client) do (
CD ./%%p
for %%I in (win-x64,osx-x64,linux-x64) do (
- dotnet publish -o=../publish/%%p.%%I -c=release -r=%%I --nologo & 7z a -tzip ../publish/%%p.%%I.zip ../publish/%%p.%%I
+ dotnet publish -o=../publish/%%p.%%I -c=release -r=%%I -f=netcoreapp3.1 & 7z a -tzip ../publish/%%p.%%I.zip ../publish/%%p.%%I
)
cd ../
)