コード例 #1
0
        public async Task <ActionResponse> ExecuteAsync(string baseUrl, IRestRequest request, string userAgent = "HandlerAutomation", int timeout = 2000)
        {
            var res = new ActionResponse();

            try
            {
                request.AddHeader("Accept", "application/json");
                request.AddHeader("Content-Type", "application/json");
                request.RequestFormat = DataFormat.Json;

                var client = new RestClient {
                    BaseUrl = new Uri(baseUrl), FollowRedirects = false, Timeout = timeout > 0 ? timeout : 2000
                };
                client.UserAgent = userAgent;

                _logHandler.Info($"Send {request.Method} to endpoint {request.Resource}");

                var response = await client.ExecuteAsync(request);

                var responseContent = JsonConvert.DeserializeObject <HandlerResponse>(response.Content);

                if (response.ErrorException == null && (int)response.StatusCode < 400)
                {
                    res = new ActionResponse()
                    {
                        Content    = responseContent,
                        StatusCode = response.StatusCode
                    };

                    _logHandler.Info("Response", res.Content);
                }
                else
                {
                    res = new ActionResponse()
                    {
                        StatusCode = response != null ? response.StatusCode : HttpStatusCode.InternalServerError,
                        Error      = responseContent != null
                        ? responseContent?.ErrorReason
                        : (response != null ? response.ErrorException.Message?.ToString() : "Uknown Erorr"),
                        Content = responseContent,
                    };

                    _logHandler.Error("Bad response", res);
                }
            }
            catch (Exception ex)
            {
                res = new ActionResponse()
                {
                    StatusCode = HttpStatusCode.InternalServerError,
                    Error      = $"Unknown Exception: {((RestException)ex)?.InnerException}, Message: {((RestException)ex)?.Message}",
                    Content    = null
                };
                _logHandler.Error("Exception", res);
            }
            return(res);
        }
コード例 #2
0
        /// <summary>
        /// Write error message to log
        /// </summary>
        /// <param name="logHandler"></param>
        /// <param name="text">Message</param>
        /// <param name="args">Arguments to format.</param>
        public static void Error(this ILogHandler logHandler, string text, params object[] args)
        {
            if (logHandler == null)
            {
                throw new ArgumentNullException("logHandler", "Log Handler cannot be null");
            }

            logHandler.Error(string.Format(text, args));
        }
コード例 #3
0
        public void TearDown()
        {
            var CurrentTest   = TestContext.CurrentContext.Test.Name;
            var CurrentStatus = TestContext.CurrentContext.Result.Outcome.Status;

            if (CurrentStatus == TestStatus.Passed)
            {
                logger.Info($"Test: {CurrentTest} - {CurrentStatus}");
                logger.Info(TestContext.CurrentContext.Result.Message);
            }
            else
            {
                logger.Error($"Test: {CurrentTest} - {CurrentStatus}");
                logger.Error(TestContext.CurrentContext.Result.Message);
            }

            logger.Info($"Test END");
        }
コード例 #4
0
ファイル: Log.cs プロジェクト: Algo-Trading-App/MoneyTree
 /// <summary>
 /// Log error
 /// </summary>
 /// <param name="error">String Error</param>
 /// <param name="overrideMessageFloodProtection">Force sending a message, overriding the "do not flood" directive</param>
 public static void Error(string error, bool overrideMessageFloodProtection = false)
 {
     try
     {
         if (error == _lastErrorText && !overrideMessageFloodProtection)
         {
             return;
         }
         _logHandler.Error(error);
         _lastErrorText = error; //Stop message flooding filling diskspace.
     }
     catch (Exception err)
     {
         Console.WriteLine("Log.Error(): Error writing error: " + err.Message);
     }
 }
コード例 #5
0
 /// <summary>
 /// Write error message to log
 /// </summary>
 /// <param name="text">The error text to log</param>
 public void Error(string text)
 {
     WriteMessage(LogType.Error, text);
     _fileLogger.Error(text);
 }
コード例 #6
0
 internal static void Error(object message) => handler.Error(message);
コード例 #7
0
 public virtual void OnUdpMessageReceivedError(UdpReceiveResult result, UdpMessage message, Exception exception)
 {
     Logger.Error(string.Format("Exception processing message from {0}, {1}", result.RemoteEndPoint, message != null ? message.GetType().Name : "(null)"), exception);
 }