mirror of
https://github.com/FastTunnel/FastTunnel.git
synced 2025-02-08 02:39:29 +08:00
Merge branch 'master' of https://github.com/SpringHgui/FastTunnel
This commit is contained in:
commit
aa1773f8de
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -20,4 +20,8 @@
|
|||
<PackageReference Include="NLog.Extensions.Logging" Version="1.6.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Logger\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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}" });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue
Block a user