mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-16 12:18:09 +00:00
[MT5] logging improvements
This commit is contained in:
+21
-1
@@ -48,7 +48,12 @@ namespace MtApi5
|
|||||||
#region Public Methods
|
#region Public Methods
|
||||||
public MtApi5Client()
|
public MtApi5Client()
|
||||||
{
|
{
|
||||||
LogConfigurator.Setup(LogProfileName);
|
#if (DEBUG)
|
||||||
|
const LogLevel logLevel = LogLevel.Debug;
|
||||||
|
#else
|
||||||
|
const LogLevel logLevel = LogLevel.Info;
|
||||||
|
#endif
|
||||||
|
LogConfigurator.Setup(LogProfileName, logLevel);
|
||||||
|
|
||||||
_mtEventHandlers[Mt5EventTypes.OnBookEvent] = ReceivedOnBookEvent;
|
_mtEventHandlers[Mt5EventTypes.OnBookEvent] = ReceivedOnBookEvent;
|
||||||
_mtEventHandlers[Mt5EventTypes.OnTick] = ReceivedOnTickEvent;
|
_mtEventHandlers[Mt5EventTypes.OnTick] = ReceivedOnTickEvent;
|
||||||
@@ -64,6 +69,7 @@ namespace MtApi5
|
|||||||
///<param name="port">Port of host connection (default 8222) </param>
|
///<param name="port">Port of host connection (default 8222) </param>
|
||||||
public void BeginConnect(string host, int port)
|
public void BeginConnect(string host, int port)
|
||||||
{
|
{
|
||||||
|
Log.Info($"BeginConnect: host = {host}, port = {port}");
|
||||||
Task.Factory.StartNew(() => Connect(host, port));
|
Task.Factory.StartNew(() => Connect(host, port));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,6 +79,7 @@ namespace MtApi5
|
|||||||
///<param name="port">Port of host connection (default 8222) </param>
|
///<param name="port">Port of host connection (default 8222) </param>
|
||||||
public void BeginConnect(int port)
|
public void BeginConnect(int port)
|
||||||
{
|
{
|
||||||
|
Log.Info($"BeginConnect: port = {port}");
|
||||||
Task.Factory.StartNew(() => Connect(port));
|
Task.Factory.StartNew(() => Connect(port));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,6 +88,7 @@ namespace MtApi5
|
|||||||
///</summary>
|
///</summary>
|
||||||
public void BeginDisconnect()
|
public void BeginDisconnect()
|
||||||
{
|
{
|
||||||
|
Log.Info("BeginDisconnect called.");
|
||||||
Task.Factory.StartNew(() => Disconnect(false));
|
Task.Factory.StartNew(() => Disconnect(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3351,6 +3359,8 @@ namespace MtApi5
|
|||||||
{
|
{
|
||||||
client.Dispose();
|
client.Dispose();
|
||||||
message = string.IsNullOrEmpty(client.Host) ? $"Failed connection to localhost:{client.Port}. {e.Message}" : $"Failed connection to {client.Host}:{client.Port}. {e.Message}";
|
message = string.IsNullOrEmpty(client.Host) ? $"Failed connection to localhost:{client.Port}. {e.Message}" : $"Failed connection to {client.Host}:{client.Port}. {e.Message}";
|
||||||
|
|
||||||
|
Log.Warn(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state == Mt5ConnectionState.Connected)
|
if (state == Mt5ConnectionState.Connected)
|
||||||
@@ -3363,6 +3373,8 @@ namespace MtApi5
|
|||||||
_client.ServerFailed += _client_ServerFailed;
|
_client.ServerFailed += _client_ServerFailed;
|
||||||
_client.MtEventReceived += _client_MtEventReceived;
|
_client.MtEventReceived += _client_MtEventReceived;
|
||||||
message = string.IsNullOrEmpty(client.Host) ? $"Connected to localhost:{client.Port}" : $"Connected to { client.Host}:{client.Port}";
|
message = string.IsNullOrEmpty(client.Host) ? $"Connected to localhost:{client.Port}" : $"Connected to { client.Host}:{client.Port}";
|
||||||
|
|
||||||
|
Log.Info(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
_connectionState = state;
|
_connectionState = state;
|
||||||
@@ -3477,6 +3489,8 @@ namespace MtApi5
|
|||||||
_connectionState = state;
|
_connectionState = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.Info(message);
|
||||||
|
|
||||||
ConnectionStateChanged?.Invoke(this, new Mt5ConnectionEventArgs(state, message));
|
ConnectionStateChanged?.Invoke(this, new Mt5ConnectionEventArgs(state, message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3487,6 +3501,7 @@ namespace MtApi5
|
|||||||
var client = Client;
|
var client = Client;
|
||||||
if (client == null)
|
if (client == null)
|
||||||
{
|
{
|
||||||
|
Log.Warn("SendCommand: No connection");
|
||||||
throw new Exception("No connection");
|
throw new Exception("No connection");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3496,16 +3511,19 @@ namespace MtApi5
|
|||||||
}
|
}
|
||||||
catch (CommunicationException ex)
|
catch (CommunicationException ex)
|
||||||
{
|
{
|
||||||
|
Log.Warn($"SendCommand: {ex.Message}");
|
||||||
throw new Exception(ex.Message, ex);
|
throw new Exception(ex.Message, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response == null)
|
if (response == null)
|
||||||
{
|
{
|
||||||
|
Log.Warn("SendCommand: Response from MetaTrader is null");
|
||||||
throw new ExecutionException(ErrorCode.ErrCustom, "Response from MetaTrader is null");
|
throw new ExecutionException(ErrorCode.ErrCustom, "Response from MetaTrader is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.ErrorCode != 0)
|
if (response.ErrorCode != 0)
|
||||||
{
|
{
|
||||||
|
Log.Warn($"SendCommand: ErrorCode = {response.ErrorCode}. {response}");
|
||||||
throw new ExecutionException((ErrorCode)response.ErrorCode, response.ToString());
|
throw new ExecutionException((ErrorCode)response.ErrorCode, response.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3529,12 +3547,14 @@ namespace MtApi5
|
|||||||
|
|
||||||
if (res == null)
|
if (res == null)
|
||||||
{
|
{
|
||||||
|
Log.Warn("SendRequest: Response from MetaTrader is null");
|
||||||
throw new ExecutionException(ErrorCode.ErrCustom, "Response from MetaTrader is null");
|
throw new ExecutionException(ErrorCode.ErrCustom, "Response from MetaTrader is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
var response = JsonConvert.DeserializeObject<Response<T>>(res);
|
var response = JsonConvert.DeserializeObject<Response<T>>(res);
|
||||||
if (response.ErrorCode != 0)
|
if (response.ErrorCode != 0)
|
||||||
{
|
{
|
||||||
|
Log.Warn($"SendRequest: ErrorCode = {response.ErrorCode}. {response}");
|
||||||
throw new ExecutionException((ErrorCode)response.ErrorCode, response.ErrorMessage);
|
throw new ExecutionException((ErrorCode)response.ErrorCode, response.ErrorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user