This commit is contained in:
SpringHgui 2020-01-08 11:05:43 +08:00
commit aa1773f8de
10 changed files with 27 additions and 66 deletions

View File

@ -2,7 +2,6 @@
using Microsoft.Extensions.DependencyInjection;
using FastTunnel.Core;
using FastTunnel.Core.Client;
using FastTunnel.Core.Logger;
using System;
using System.IO;
using System.Net;
@ -20,7 +19,9 @@ namespace FastTunnel.Client
{
static void Main(string[] args)
{
LogManager.LoadConfiguration("Nlog.config");
var logger = LogManager.GetCurrentClassLogger();
logger.Debug("===== Sevice Start =====");
try
{

View File

@ -1,7 +1,6 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using FastTunnel.Core.Config;
using FastTunnel.Core.Logger;
using FastTunnel.Core.Models;
using System;
using System.Collections.Generic;

View File

@ -20,4 +20,8 @@
<PackageReference Include="NLog.Extensions.Logging" Version="1.6.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="Logger\" />
</ItemGroup>
</Project>

View File

@ -1,5 +1,4 @@
using FastTunnel.Core.Logger;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Net;
@ -71,7 +70,14 @@ namespace FastTunnel.Core
private void ReceiveCustomer(object state)
{
var client = state as Socket;
handler.Invoke(client, _data);
try
{
handler.Invoke(client, _data);
}
catch (Exception ex)
{
_logerr.LogError(ex);
}
}
public void ShutdownAndClose()

View File

@ -1,34 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace FastTunnel.Core.Logger
{
public class ConsoleLogger : ILogger
{
public void Error(object msg)
{
Console.WriteLine(string.Format("Erro - {0}", msg?.ToString()));
}
public void LogDebug(string msg)
{
Console.WriteLine(string.Format("Debu - {0}", msg));
}
public void Error(string msg)
{
Console.WriteLine(string.Format("Erro - {0}", msg));
}
public void Info(string msg)
{
Console.WriteLine(string.Format("Info - {0}", msg));
}
public void Warning(string msg)
{
Console.WriteLine(string.Format("Warn - {0}", msg));
}
}
}

View File

@ -1,19 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace FastTunnel.Core.Logger
{
public interface ILogger
{
void Error(object msg);
void Error(string msg);
void Warning(string msg);
void LogDebug(string msg);
void Info(string msg);
}
}

View File

@ -3,7 +3,6 @@ using Newtonsoft.Json.Linq;
using FastTunnel.Core.Config;
using FastTunnel.Core.Exceptions;
using FastTunnel.Core.Extensions;
using FastTunnel.Core.Logger;
using FastTunnel.Core.Models;
using System;
using System.Collections.Generic;
@ -80,8 +79,9 @@ namespace FastTunnel.Core.Server
client.Close();
return;
}
catch (Exception)
catch (Exception ex)
{
_logger.LogError(ex);
throw;
}
@ -258,6 +258,8 @@ namespace FastTunnel.Core.Server
// listen success
SSHList.Add(item.RemotePort, new SSHInfo<SSHHandlerArg> { Listener = ls, Socket = client, SSHConfig = item });
_logger.LogDebug($"SSH proxy success: {item.RemotePort} -> {item.LocalIp}:{item.LocalPort}");
client.Send(new Message<string> { MessageType = MessageType.Info, Content = $"TunnelForSSH is OK: {requet.ClientConfig.Common.ServerAddr}:{item.RemotePort}->{item.LocalIp}:{item.LocalPort}" });
}
catch (Exception ex)
{
@ -266,8 +268,6 @@ namespace FastTunnel.Core.Server
client.Send(new Message<string> { MessageType = MessageType.Error, Content = ex.Message });
continue;
}
client.Send(new Message<string> { MessageType = MessageType.Info, Content = $"TunnelForSSH is OK: {requet.ClientConfig.Common.ServerAddr}:{item.RemotePort}->{item.LocalIp}:{item.LocalPort}" });
}
}

View File

@ -1,5 +1,6 @@
<?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>

View File

@ -1,6 +1,5 @@
using Microsoft.Extensions.Configuration;
using FastTunnel.Core;
using FastTunnel.Core.Logger;
using FastTunnel.Core.Server;
using System;
using System.Collections.Generic;
@ -26,8 +25,9 @@ namespace FastTunnel.Server
static void Main(string[] args)
{
Console.WriteLine("Server Start!");
LogManager.LoadConfiguration("Nlog.config");
var logger = LogManager.GetCurrentClassLogger();
logger.Debug("===== Sevice Start =====");
try
{
@ -37,8 +37,8 @@ namespace FastTunnel.Server
catch (Exception ex)
{
// NLog: catch any exception and log it.
logger.Error(ex, "Stopped program because of exception");
throw;
logger.Error(ex);
Console.WriteLine(ex);
}
finally
{

View File

@ -10,5 +10,8 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<TargetFramework>netcoreapp3.1</TargetFramework>
<PublishDir>bin\Release\netcoreapp3.1\publish\</PublishDir>
<SelfContained>false</SelfContained>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<PublishSingleFile>False</PublishSingleFile>
<PublishReadyToRun>False</PublishReadyToRun>
</PropertyGroup>
</Project>