Пример #1
0
        protected virtual void SendBatchLogs(List <WebLogMessage> webLogs)
        {
            // если канал оффлайн, то ничего не отправляем
            if (Client.CanSendData == false)
            {
                LogQueue.AddRange(webLogs);
                return;
            }

            Client.InternalLog.DebugFormat("SendBatchLogs {0}", webLogs.Count);

            var logs = webLogs.Select(webLog =>
            {
                var log = new SendLogData()
                {
                    ComponentId = webLog.ComponentControl.Info.Id,
                    Date        = webLog.Date,
                    Order       = webLog.Order,
                    Level       = webLog.Level,
                    Message     = webLog.Message,
                    Context     = webLog.Context
                };
                log.Properties.CopyFrom(webLog.Properties);
                return(log);
            }).ToArray();

            var now      = DateTime.Now;
            var response = Client.ApiService.SendLogs(logs);

            Client.InternalLog.DebugFormat("ApiService.SendLogs, count: {0}, time: {1}", webLogs.Count, DateTime.Now - now);

            if (!response.Success)
            {
                Client.InternalLog.WarningFormat("Failed ApiService.SendLogs, code: {0}, error: {1}", response.Code, response.ErrorMessage);
                foreach (var webLog in webLogs)
                {
                    webLog.Attemps++;
                    webLog.LastAttempTime = now;
                }
                LogQueue.AddRange(webLogs);
            }
        }