ApiController - Add Log
This commit is contained in:
parent
b020ca2a73
commit
b4baa218b4
|
@ -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<CardInformation> 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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user