Поставил нормальный логгер
This commit is contained in:
@@ -5,6 +5,6 @@ namespace SfeduSchedule
|
|||||||
public static class GlobalVariables
|
public static class GlobalVariables
|
||||||
{
|
{
|
||||||
public static string JwtFilePath { get; set; } = "data/jwt.txt";
|
public static string JwtFilePath { get; set; } = "data/jwt.txt";
|
||||||
public static readonly JsonSerializerOptions jsonSerializerOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
|
public static readonly JsonSerializerOptions jsonSerializerOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,11 @@ namespace SfeduSchedule.Services
|
|||||||
System.Text.Encoding.UTF8, "application/json");
|
System.Text.Encoding.UTF8, "application/json");
|
||||||
var response = await _httpClient.SendAsync(request);
|
var response = await _httpClient.SendAsync(request);
|
||||||
_logger.LogInformation("GetScheduleAsync: Ответ получен: {StatusCode}", response.StatusCode);
|
_logger.LogInformation("GetScheduleAsync: Ответ получен: {StatusCode}", response.StatusCode);
|
||||||
response.EnsureSuccessStatusCode();
|
if (response.StatusCode != System.Net.HttpStatusCode.OK)
|
||||||
|
{
|
||||||
|
_logger.LogError("GetScheduleAsync: Ошибка при получении списка студентов: {StatusCode}", response.StatusCode);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return await response.Content.ReadAsStringAsync();
|
return await response.Content.ReadAsStringAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +47,11 @@ namespace SfeduSchedule.Services
|
|||||||
System.Text.Encoding.UTF8, "application/json");
|
System.Text.Encoding.UTF8, "application/json");
|
||||||
var response = await _httpClient.SendAsync(request);
|
var response = await _httpClient.SendAsync(request);
|
||||||
_logger.LogInformation("SearchRoomsAsync: Ответ получен: {StatusCode}", response.StatusCode);
|
_logger.LogInformation("SearchRoomsAsync: Ответ получен: {StatusCode}", response.StatusCode);
|
||||||
response.EnsureSuccessStatusCode();
|
if (response.StatusCode != System.Net.HttpStatusCode.OK)
|
||||||
|
{
|
||||||
|
_logger.LogError("SearchRoomsAsync: Ошибка при получении списка студентов: {StatusCode}", response.StatusCode);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return await response.Content.ReadAsStringAsync();
|
return await response.Content.ReadAsStringAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +68,11 @@ namespace SfeduSchedule.Services
|
|||||||
var response = await _httpClient.SendAsync(request);
|
var response = await _httpClient.SendAsync(request);
|
||||||
|
|
||||||
_logger.LogInformation("GetGuidAsync: Ответ получен: {StatusCode}", response.StatusCode);
|
_logger.LogInformation("GetGuidAsync: Ответ получен: {StatusCode}", response.StatusCode);
|
||||||
response.EnsureSuccessStatusCode();
|
if (response.StatusCode != System.Net.HttpStatusCode.OK)
|
||||||
|
{
|
||||||
|
_logger.LogError("GetGuidAsync: Ошибка при получении списка студентов: {StatusCode}", response.StatusCode);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
var json = await response.Content.ReadAsStringAsync();
|
var json = await response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
@@ -89,8 +101,8 @@ namespace SfeduSchedule.Services
|
|||||||
var schedule = await GetScheduleAsync(msr);
|
var schedule = await GetScheduleAsync(msr);
|
||||||
if (schedule == null)
|
if (schedule == null)
|
||||||
{
|
{
|
||||||
_logger.LogError("GetScheduleJsonAsync: Schedule is null. Request: {@msr}", msr);
|
_logger.LogError("GetScheduleJsonAsync: Schedule is null. Request: " + JsonSerializer.Serialize(msr, GlobalVariables.jsonSerializerOptions));
|
||||||
throw new Exception("Schedule is null"); // Недопустимое состояние
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Schedule? scheduleJson;
|
Schedule? scheduleJson;
|
||||||
@@ -101,23 +113,23 @@ namespace SfeduSchedule.Services
|
|||||||
{
|
{
|
||||||
case null:
|
case null:
|
||||||
_logger.LogError(
|
_logger.LogError(
|
||||||
"GetScheduleJsonAsync: scheduleJson is null. Schedule: {Schedule}\n Request: {@msr}",
|
"GetScheduleJsonAsync: scheduleJson is null. Schedule: {Schedule}\n Request: {msr}",
|
||||||
schedule, msr);
|
schedule, JsonSerializer.Serialize(msr, GlobalVariables.jsonSerializerOptions));
|
||||||
break;
|
break;
|
||||||
case { Embedded: null }:
|
case { Embedded: null }:
|
||||||
_logger.LogError(
|
_logger.LogError(
|
||||||
"GetScheduleJsonAsync: scheduleJson.Embedded is null. scheduleJson: {@scheduleJson}\n Request: {@msr}",
|
"GetScheduleJsonAsync: scheduleJson.Embedded is null. scheduleJson: {@scheduleJson}\n Request: {msr}",
|
||||||
scheduleJson, msr);
|
scheduleJson, JsonSerializer.Serialize(msr, GlobalVariables.jsonSerializerOptions));
|
||||||
break;
|
break;
|
||||||
case { Embedded.Events: null }:
|
case { Embedded.Events: null }:
|
||||||
_logger.LogError(
|
_logger.LogError(
|
||||||
"GetScheduleJsonAsync: scheduleJson.Embedded.Events is null. Embedded: {@Embedded}\n Request: {@msr}",
|
"GetScheduleJsonAsync: scheduleJson.Embedded.Events is null. Embedded: {@Embedded}\n Request: {msr}",
|
||||||
scheduleJson.Embedded, msr);
|
scheduleJson.Embedded, JsonSerializer.Serialize(msr, GlobalVariables.jsonSerializerOptions));
|
||||||
break;
|
break;
|
||||||
case { Embedded.Events.Length: 0 }:
|
case { Embedded.Events.Length: 0 }:
|
||||||
_logger.LogWarning(
|
_logger.LogWarning(
|
||||||
"GetScheduleJsonAsync: scheduleJson.Embedded.Events is empty. Embedded: {@Embedded}\n Request: {@msr}",
|
"GetScheduleJsonAsync: scheduleJson.Embedded.Events is empty. Embedded: {@Embedded}\n Request: {msr}",
|
||||||
scheduleJson.Embedded, msr);
|
scheduleJson.Embedded, JsonSerializer.Serialize(msr, GlobalVariables.jsonSerializerOptions));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return scheduleJson;
|
return scheduleJson;
|
||||||
@@ -126,8 +138,8 @@ namespace SfeduSchedule.Services
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex,
|
_logger.LogError(ex,
|
||||||
"GetScheduleJsonAsync: Deserialization failed. Schedule: {Schedule}\n Request: {@msr}", schedule,
|
"GetScheduleJsonAsync: Deserialization failed. Schedule: {Schedule}\n Request: {msr}", schedule,
|
||||||
msr);
|
JsonSerializer.Serialize(msr, GlobalVariables.jsonSerializerOptions));
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -138,7 +150,7 @@ namespace SfeduSchedule.Services
|
|||||||
Schedule? scheduleJson = await GetScheduleJsonAsync(msr);
|
Schedule? scheduleJson = await GetScheduleJsonAsync(msr);
|
||||||
if (scheduleJson == null)
|
if (scheduleJson == null)
|
||||||
{
|
{
|
||||||
_logger.LogError("GetIcsAsync: scheduleJson is null after deserialization. Request: {@msr}", msr);
|
_logger.LogError("GetIcsAsync: scheduleJson is null after deserialization. Request: " + JsonSerializer.Serialize(msr, GlobalVariables.jsonSerializerOptions));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user