改变nlog配置的方式

This commit is contained in:
SpringHgui 2020-04-09 10:34:59 +08:00
parent ecc92c6189
commit fa12071d6d
16 changed files with 38 additions and 97 deletions

View File

@ -26,9 +26,6 @@
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Nlog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ProjectExtensions>

View File

@ -1,17 +0,0 @@
<?xml version="1.0" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target xsi:type="File" name="file"
layout="${longdate} ${logger} ${message}${exception:format=ToString}"
fileName="${basedir}/Logs/${shortdate}.${level}.log" />
<target xsi:type="Console" name="console"
layout="${date}|${level:uppercase=true}|${message} ${exception} ${all-event-properties}" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file,console" />
</rules>
</nlog>

View File

@ -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 =====");

View File

@ -7,12 +7,6 @@
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Compile Remove="Logger\**" />
<EmbeddedResource Remove="Logger\**" />
<None Remove="Logger\**" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Core\SuiDaoServer.cs.BASE.cs" />
<Compile Remove="Core\SuiDaoServer.cs.LOCAL.cs" />

View File

@ -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;
}
}
}

View File

@ -28,9 +28,6 @@
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Nlog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -1,18 +0,0 @@
<?xml version="1.0" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
throwExceptions="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target xsi:type="File" name="file"
layout="${longdate} ${logger} ${message}${exception:format=ToString}"
fileName="${basedir}/Logs/${shortdate}.${level}.log" />
<target xsi:type="Console" name="console"
layout="${date}|${level:uppercase=true}|${message} ${exception}| ${all-event-properties}" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file,console" />
</rules>
</nlog>

View File

@ -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 =====");

View File

@ -1,17 +0,0 @@
<?xml version="1.0" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target xsi:type="File" name="file"
layout="${longdate} ${logger} ${message}${exception:format=ToString}"
fileName="${basedir}/Logs/${shortdate}.${level}.log" />
<target xsi:type="Console" name="console"
layout="${date}|${level:uppercase=true}|${message} ${exception} ${all-event-properties}" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file,console" />
</rules>
</nlog>

View File

@ -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
/// <param name="args"></param>
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))

View File

@ -14,10 +14,4 @@
<ProjectReference Include="..\FastTunnel.Core\FastTunnel.Core.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="Nlog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -3,7 +3,7 @@
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="dotnet-core" value="https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="dotnet-core" value="https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json" />
</packageSources>
</configuration>

View File

@ -1,17 +0,0 @@
<?xml version="1.0" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target xsi:type="File" name="file"
layout="${longdate} ${logger} ${message}${exception:format=ToString}"
fileName="${basedir}/Logs/${shortdate}.${level}.log" />
<target xsi:type="Console" name="console"
layout="${date}|${level:uppercase=true}|${message} ${exception} ${all-event-properties}" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file,console" />
</rules>
</nlog>

View File

@ -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 =====");

View File

@ -19,9 +19,6 @@
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Nlog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -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 ../
)