From b4baa218b4aa11efd33dfc6bab0f3d3dbb931e9a Mon Sep 17 00:00:00 2001 From: DucDangAnh Date: Tue, 14 Jul 2020 17:06:32 +0700 Subject: [PATCH] ApiController - Add Log --- AIParkingApplication/ApiController.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/AIParkingApplication/ApiController.cs b/AIParkingApplication/ApiController.cs index 452dde2..4cf05d4 100644 --- a/AIParkingApplication/ApiController.cs +++ b/AIParkingApplication/ApiController.cs @@ -13,9 +13,11 @@ namespace AIParkingApplication private HttpClient httpClient; private bool isHttpClientDisposabled; private int numberOfRetry; + private Logger applicationLogger; public ApiController(string serverIPAddress, Logger applicationLogger, int numberOfRetry = 3) { + this.applicationLogger = applicationLogger; httpClient = new HttpClient { BaseAddress = new Uri($"http://{serverIPAddress}"), @@ -72,12 +74,14 @@ namespace AIParkingApplication catch (Exception ex) { Console.WriteLine($"GetStatisticInfo Exception:\t{DateTime.Now.GetTimeFormatted()} \t {ex.Message}"); + applicationLogger.Log(LogLevel.Info, $"Query dữ liệu thống kê bãi xe lỗi. exMessage: {ex.Message}"); return null; } } public async Task GetCardInformation(string cardNumber) { + int requestCounter = 1; try { var request = new CardModel() @@ -85,7 +89,6 @@ namespace AIParkingApplication CardNumber = cardNumber }; HttpResponseMessage response; - int requestCounter = 1; do { response = await httpClient.PostAsJsonAsync("/api/check-card", request); @@ -101,6 +104,7 @@ namespace AIParkingApplication catch (Exception ex) { Console.WriteLine($"CheckCard Exception:\t{DateTime.Now.GetTimeFormatted()} \t {ex.Message}"); + applicationLogger.Log(LogLevel.Info, $"Query thông tin thẻ lỗi. Thẻ số: {cardNumber} | số lần thử lại: {requestCounter} | exMessage: {ex.Message}"); return null; } } @@ -112,6 +116,8 @@ namespace AIParkingApplication string plateImageResultBase64 = Convert.ToBase64String(plateImageResult.ToBytes()); string plateFrameImageBase64 = Convert.ToBase64String(plateFrameImage.ToBytes()); string frameImageBase64 = Convert.ToBase64String(frameImage.ToBytes()); + + int requestCounter = 1; try { var request = new SaveLogModel @@ -129,7 +135,7 @@ namespace AIParkingApplication FrameImage = frameImageBase64 }; HttpResponseMessage response; - int requestCounter = 1; + do { response = await httpClient.PostAsJsonAsync("/api/save-logs", request); @@ -143,6 +149,7 @@ namespace AIParkingApplication catch (Exception ex) { Console.WriteLine($"SaveLog Exception:\t{DateTime.Now.GetTimeFormatted()} \t {ex.Message}"); + applicationLogger.Log(LogLevel.Info, string.Format("Không thể lưu log gửi xe. Làn: {0} | Mã thẻ: {1} | cameraID: {2} | Thời gian: {3} | Biển số: {4} | LogID: {5} | exMessage: ", direction == LaneDirection.In ? "IN" : "OUT", cardID, cameraID, timestamp, plateString, logID, ex.Message)); return new SaveLogRespone(); } }