fixing dotnets terrible logging

This commit is contained in:
2023-12-05 15:30:33 -07:00
parent a77c001601
commit e8aef7357a
16 changed files with 134 additions and 95 deletions

View File

@@ -8,17 +8,17 @@ public class CanvasAssignmentGroupService
{
private readonly IWebRequestor webRequestor;
private readonly CanvasServiceUtils utils;
private readonly ILogger<CanvasAssignmentGroupService> log;
private readonly MyLogger<CanvasAssignmentGroupService> logger;
public CanvasAssignmentGroupService(
IWebRequestor webRequestor,
CanvasServiceUtils utils,
ILogger<CanvasAssignmentGroupService> logger
MyLogger<CanvasAssignmentGroupService> logger
)
{
this.webRequestor = webRequestor;
this.utils = utils;
this.log = logger;
this.logger = logger;
}
public async Task<IEnumerable<CanvasAssignmentGroup>> GetAll(ulong courseId)
{
@@ -35,7 +35,7 @@ public class CanvasAssignmentGroupService
LocalAssignmentGroup localAssignmentGroup
)
{
log.LogInformation($"creating assignment group: {localAssignmentGroup.Name}");
logger.Log($"creating assignment group: {localAssignmentGroup.Name}");
var url = $"courses/{canvasCourseId}/assignment_groups";
var request = new RestRequest(url);
var body = new
@@ -59,7 +59,7 @@ public class CanvasAssignmentGroupService
LocalAssignmentGroup localAssignmentGroup
)
{
log.LogInformation($"updating assignment group: {localAssignmentGroup.Name}");
logger.Log($"updating assignment group: {localAssignmentGroup.Name}");
if (localAssignmentGroup.CanvasId == null)
throw new Exception("cannot update assignment group if canvas id is null");
var url = $"courses/{canvasCourseId}/assignment_groups/{localAssignmentGroup.CanvasId}";

View File

@@ -12,7 +12,7 @@ public class CanvasService
{
private readonly IWebRequestor webRequestor;
private readonly CanvasServiceUtils utils;
private readonly ILogger<CanvasService> logger;
private readonly MyLogger<CanvasService> logger;
public CanvasAssignmentService Assignments { get; }
public CanvasAssignmentGroupService AssignmentGroups { get; }
@@ -26,7 +26,7 @@ public class CanvasService
CanvasAssignmentGroupService AssignmentGroups,
CanvasModuleService Modules,
CanvasQuizService Quizzes,
ILogger<CanvasService> logger
MyLogger<CanvasService> logger
)
{
this.webRequestor = webRequestor;
@@ -64,8 +64,8 @@ public class CanvasService
if (data == null)
{
logger.LogError(response.Content);
logger.LogError(response.ResponseUri?.ToString());
logger.Error(response.Content);
logger.Error(response.ResponseUri?.ToString());
throw new Exception("error getting course from canvas");
}
return data;
@@ -95,7 +95,7 @@ public class CanvasService
CanvasModuleItem item
)
{
logger.LogInformation($"updating module item {item.Title}");
logger.Log($"updating module item {item.Title}");
var url = $"courses/{canvasCourseId}/modules/{canvasModuleId}/items/{item.Id}";
var body = new { module_item = new { title = item.Title, position = item.Position } };
var request = new RestRequest(url);
@@ -114,7 +114,7 @@ public class CanvasService
ulong contentId
)
{
logger.LogInformation($"creating new module item {title}");
logger.Log($"creating new module item {title}");
var url = $"courses/{canvasCourseId}/modules/{canvasModuleId}/items";
var body = new
{