mirror of
https://github.com/FastTunnel/FastTunnel.git
synced 2025-02-08 02:39:29 +08:00
a
This commit is contained in:
parent
0919d31c9c
commit
8ebfc2d137
17
FastTunnel.Client/Nlog.config
Normal file
17
FastTunnel.Client/Nlog.config
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?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}|${logger}|${all-event-properties}" />
|
||||
</targets>
|
||||
|
||||
<rules>
|
||||
<logger name="*" minlevel="Debug" writeTo="file,console" />
|
||||
</rules>
|
||||
</nlog>
|
15
FastTunnel.Core/Extensions/LogExtentions.cs
Normal file
15
FastTunnel.Core/Extensions/LogExtentions.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace FastTunnel.Core.Extensions
|
||||
{
|
||||
public static class LogExtentions
|
||||
{
|
||||
public static void LogError(this ILogger logger, object ex)
|
||||
{
|
||||
logger.LogError(ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
51
FastTunnel.Core/Host/Host.cs
Normal file
51
FastTunnel.Core/Host/Host.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
using FastTunnel.Core.Config;
|
||||
using FastTunnel.Core.Server;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace FastTunnel.Core.Host
|
||||
{
|
||||
public class Host
|
||||
{
|
||||
private ServiceCollection ServiceCollection;
|
||||
|
||||
public Host()
|
||||
{
|
||||
var config = new ConfigurationBuilder()
|
||||
.SetBasePath(System.IO.Directory.GetCurrentDirectory()) //From NuGet Package Microsoft.Extensions.Configuration.Json
|
||||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.Build();
|
||||
|
||||
Init(config);
|
||||
}
|
||||
|
||||
public void Init(IConfiguration config)
|
||||
{
|
||||
ServiceCollection = new ServiceCollection();
|
||||
ServiceCollection.AddLogging(loggingBuilder =>
|
||||
{
|
||||
// configure Logging with NLog
|
||||
loggingBuilder.ClearProviders();
|
||||
loggingBuilder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
|
||||
loggingBuilder.AddNLog(config);
|
||||
});
|
||||
}
|
||||
|
||||
public Host Config(Action<ServiceCollection> fun)
|
||||
{
|
||||
fun.Invoke(ServiceCollection);
|
||||
return this;
|
||||
}
|
||||
|
||||
public IServiceProvider Build()
|
||||
{
|
||||
return ServiceCollection.BuildServiceProvider();
|
||||
}
|
||||
}
|
||||
}
|
17
FastTunnel.Server/Nlog.config
Normal file
17
FastTunnel.Server/Nlog.config
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?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}|${logger}|${all-event-properties}" />
|
||||
</targets>
|
||||
|
||||
<rules>
|
||||
<logger name="*" minlevel="Debug" writeTo="file,console" />
|
||||
</rules>
|
||||
</nlog>
|
Loading…
Reference in New Issue
Block a user