mirror of
https://github.com/FastTunnel/FastTunnel.git
synced 2025-02-08 02:39:29 +08:00
改变nlog配置的方式
This commit is contained in:
parent
ecc92c6189
commit
fa12071d6d
|
@ -26,9 +26,6 @@
|
||||||
<None Update="appsettings.json">
|
<None Update="appsettings.json">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<None Update="Nlog.config">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ProjectExtensions>
|
<ProjectExtensions>
|
||||||
|
|
|
@ -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>
|
|
|
@ -14,6 +14,7 @@ using FastTunnel.Core.Config;
|
||||||
using FastTunnel.Core.Core;
|
using FastTunnel.Core.Core;
|
||||||
using FastTunnel.Core.Models;
|
using FastTunnel.Core.Models;
|
||||||
using FastTunnel.Core.Handlers.Client;
|
using FastTunnel.Core.Handlers.Client;
|
||||||
|
using FastTunnel.Core.Logger;
|
||||||
|
|
||||||
namespace FastTunnel.Client
|
namespace FastTunnel.Client
|
||||||
{
|
{
|
||||||
|
@ -21,7 +22,7 @@ namespace FastTunnel.Client
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
LogManager.LoadConfiguration("Nlog.config");
|
LogManager.Configuration = NlogConfig.getNewConfig();
|
||||||
var logger = LogManager.GetCurrentClassLogger();
|
var logger = LogManager.GetCurrentClassLogger();
|
||||||
logger.Debug("===== FastTunnel Client Start =====");
|
logger.Debug("===== FastTunnel Client Start =====");
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,6 @@
|
||||||
<StartupObject />
|
<StartupObject />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Remove="Logger\**" />
|
|
||||||
<EmbeddedResource Remove="Logger\**" />
|
|
||||||
<None Remove="Logger\**" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Remove="Core\SuiDaoServer.cs.BASE.cs" />
|
<Compile Remove="Core\SuiDaoServer.cs.BASE.cs" />
|
||||||
<Compile Remove="Core\SuiDaoServer.cs.LOCAL.cs" />
|
<Compile Remove="Core\SuiDaoServer.cs.LOCAL.cs" />
|
||||||
|
|
26
FastTunnel.Core/Logger/NlogConfig.cs
Normal file
26
FastTunnel.Core/Logger/NlogConfig.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,9 +28,6 @@
|
||||||
<None Update="appsettings.json">
|
<None Update="appsettings.json">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<None Update="Nlog.config">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -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>
|
|
|
@ -18,6 +18,7 @@ using FastTunnel.Core.Host;
|
||||||
using FastTunnel.Core.Core;
|
using FastTunnel.Core.Core;
|
||||||
using FastTunnel.Core.Handlers;
|
using FastTunnel.Core.Handlers;
|
||||||
using FastTunnel.Core.Handlers.Server;
|
using FastTunnel.Core.Handlers.Server;
|
||||||
|
using FastTunnel.Core.Logger;
|
||||||
|
|
||||||
namespace FastTunnel.Server
|
namespace FastTunnel.Server
|
||||||
{
|
{
|
||||||
|
@ -27,7 +28,7 @@ namespace FastTunnel.Server
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
LogManager.LoadConfiguration("Nlog.config");
|
LogManager.Configuration = NlogConfig.getNewConfig();
|
||||||
var logger = LogManager.GetCurrentClassLogger();
|
var logger = LogManager.GetCurrentClassLogger();
|
||||||
logger.Debug("===== FastTunnel Server Start =====");
|
logger.Debug("===== FastTunnel Server Start =====");
|
||||||
|
|
||||||
|
|
|
@ -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>
|
|
|
@ -3,11 +3,13 @@ using FastTunnel.Core.Config;
|
||||||
using FastTunnel.Core.Core;
|
using FastTunnel.Core.Core;
|
||||||
using FastTunnel.Core.Handlers.Client;
|
using FastTunnel.Core.Handlers.Client;
|
||||||
using FastTunnel.Core.Host;
|
using FastTunnel.Core.Host;
|
||||||
|
using FastTunnel.Core.Logger;
|
||||||
using FastTunnel.Core.Models;
|
using FastTunnel.Core.Models;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
using NLog.Extensions.Logging;
|
||||||
using SuiDao.Client.Models;
|
using SuiDao.Client.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -29,9 +31,9 @@ namespace SuiDao.Client
|
||||||
/// <param name="args"></param>
|
/// <param name="args"></param>
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
LogManager.LoadConfiguration("Nlog.config");
|
LogManager.Configuration = NlogConfig.getNewConfig();
|
||||||
var logger = LogManager.GetCurrentClassLogger();
|
var logger = LogManager.GetCurrentClassLogger();
|
||||||
logger.Debug("===== SuiDao Client Start =====");
|
logger.Info("===== SuiDao Client Start =====");
|
||||||
|
|
||||||
var keyFile = Path.Combine(AppContext.BaseDirectory, KeyLogName);
|
var keyFile = Path.Combine(AppContext.BaseDirectory, KeyLogName);
|
||||||
if (!File.Exists(keyFile))
|
if (!File.Exists(keyFile))
|
||||||
|
|
|
@ -14,10 +14,4 @@
|
||||||
<ProjectReference Include="..\FastTunnel.Core\FastTunnel.Core.csproj" />
|
<ProjectReference Include="..\FastTunnel.Core\FastTunnel.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Update="Nlog.config">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<packageSources>
|
<packageSources>
|
||||||
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
|
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
|
||||||
<clear />
|
<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="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>
|
</packageSources>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
@ -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>
|
|
|
@ -3,6 +3,7 @@ using FastTunnel.Core.Core;
|
||||||
using FastTunnel.Core.Handlers;
|
using FastTunnel.Core.Handlers;
|
||||||
using FastTunnel.Core.Handlers.Server;
|
using FastTunnel.Core.Handlers.Server;
|
||||||
using FastTunnel.Core.Host;
|
using FastTunnel.Core.Host;
|
||||||
|
using FastTunnel.Core.Logger;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
@ -18,7 +19,7 @@ namespace SuiDao.Server
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
LogManager.LoadConfiguration("Nlog.config");
|
LogManager.Configuration = NlogConfig.getNewConfig();
|
||||||
var logger = LogManager.GetCurrentClassLogger();
|
var logger = LogManager.GetCurrentClassLogger();
|
||||||
logger.Debug("===== FastTunnel Server Start =====");
|
logger.Debug("===== FastTunnel Server Start =====");
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,6 @@
|
||||||
<None Update="appsettings.json">
|
<None Update="appsettings.json">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<None Update="Nlog.config">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
for /d %%p in (FastTunnel.Client,FastTunnel.Server,SuiDao.Client) do (
|
for /d %%p in (FastTunnel.Client,FastTunnel.Server,SuiDao.Client) do (
|
||||||
CD ./%%p
|
CD ./%%p
|
||||||
for %%I in (win-x64,osx-x64,linux-x64) do (
|
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 ../
|
cd ../
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user