示例#1
0
        public void Log(/*string errorLogId,*/ string applicationId /*, string userId,*/, string errorMessage, string errorCategory, Exception ex = null)
        {
            Console.WriteLine(errorMessage);
            startQueue();
            startThread();
            PostError post = new PostError();

            //post.ErrorLogID = errorLogId;
            post.ApplicationID = applicationId;
            //post.UserId = userId;
            post.ErrorMessage  = errorMessage;
            post.ErrorCategory = errorCategory;
            //post.TimeStamp = Convert.ToString(DateTime.Now);
            queue.enQ(post);
        }
示例#2
0
        private void startThread()
        {
            if (execute == 1)
            {
                execute++;
                Thread newThread = new Thread(x =>
                {
                    while (true)
                    {
                        PostError newLog = queue.deQ();
                        HitOnRest(newLog);
                        Thread.Sleep(10);
                        Console.WriteLine("Sent to rest : " + newLog.ErrorMessage);
                    }
                });

                newThread.Start();
            }
        }
示例#3
0
        public void HitOnRest(PostError post)
        {
            string     output = string.Empty;
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(String.Format(SERVICE_URL, SERVICE_PORT));
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            HttpResponseMessage response = client.PostAsync(String.Format(POST_ACTION), new StringContent(new JavaScriptSerializer().Serialize(post), Encoding.UTF8, "application/json")).Result;

            if (response.IsSuccessStatusCode)
            {
                Task <string> task = response.Content.ReadAsStringAsync(); // returns immediately
                string        temp = task.Result;                          // blocks until task completes
                output = "And the result is: " + temp.ToString();
            }
            else
            {
                output = string.Format("ERROR: {0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
            }

            Console.WriteLine(output);
        }