mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
got tracing and loggin working in opentelemetry
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using LocalModels;
|
||||
using Management.Services;
|
||||
using YamlDotNet.Serialization;
|
||||
@@ -7,21 +8,24 @@ public class FileStorageManager
|
||||
private readonly MyLogger<FileStorageManager> logger;
|
||||
private readonly CourseMarkdownLoader _courseMarkdownLoader;
|
||||
private readonly MarkdownCourseSaver _saveMarkdownCourse;
|
||||
private readonly ILogger<FileStorageManager> _otherLogger;
|
||||
private readonly string _basePath;
|
||||
|
||||
public FileStorageManager(
|
||||
MyLogger<FileStorageManager> logger,
|
||||
CourseMarkdownLoader courseMarkdownLoader,
|
||||
MarkdownCourseSaver saveMarkdownCourse
|
||||
MarkdownCourseSaver saveMarkdownCourse,
|
||||
ILogger<FileStorageManager> otherLogger
|
||||
)
|
||||
{
|
||||
using var activity = DiagnosticsConfig.Source.StartActivity("loading storage directory");
|
||||
this.logger = logger;
|
||||
_courseMarkdownLoader = courseMarkdownLoader;
|
||||
_saveMarkdownCourse = saveMarkdownCourse;
|
||||
_otherLogger = otherLogger;
|
||||
_basePath = FileConfiguration.GetBasePath();
|
||||
|
||||
this.logger.Log("Using storage directory: " + _basePath);
|
||||
|
||||
}
|
||||
public async Task SaveCourseAsync(LocalCourse course, LocalCourse? previouslyStoredCourse)
|
||||
{
|
||||
@@ -36,6 +40,7 @@ public class FileStorageManager
|
||||
|
||||
public async Task<IEnumerable<LocalCourse>> LoadSavedMarkdownCourses()
|
||||
{
|
||||
|
||||
return await _courseMarkdownLoader.LoadSavedMarkdownCourses();
|
||||
}
|
||||
|
||||
@@ -43,11 +48,18 @@ public class FileStorageManager
|
||||
{
|
||||
if(!Directory.Exists(_basePath))
|
||||
throw new DirectoryNotFoundException($"Cannot get empty directories, {_basePath} does not exist");
|
||||
|
||||
|
||||
return Directory
|
||||
.GetDirectories(_basePath, "*")
|
||||
.Where(dir => !Directory.EnumerateFileSystemEntries(dir).Any())
|
||||
.ToArray();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class DiagnosticsConfig
|
||||
{
|
||||
public const string SourceName = "canvas-management-source";
|
||||
public static ActivitySource Source = new ActivitySource(SourceName);
|
||||
}
|
||||
|
||||
@@ -128,4 +128,4 @@ public class CourseMarkdownLoader
|
||||
|
||||
return await Task.WhenAll(quizPromises);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
using System.Threading.Tasks.Sources;
|
||||
using LocalModels;
|
||||
using Management.Services;
|
||||
namespace Management.Services;
|
||||
|
||||
public class MarkdownCourseSaver
|
||||
public class MarkdownCourseSaver(MyLogger<MarkdownCourseSaver> logger)
|
||||
{
|
||||
private readonly MyLogger<MarkdownCourseSaver> logger;
|
||||
private readonly string _basePath;
|
||||
|
||||
public MarkdownCourseSaver(MyLogger<MarkdownCourseSaver> logger)
|
||||
{
|
||||
this.logger = logger;
|
||||
_basePath = FileConfiguration.GetBasePath();
|
||||
}
|
||||
private readonly MyLogger<MarkdownCourseSaver> _logger = logger;
|
||||
private readonly string _basePath = FileConfiguration.GetBasePath();
|
||||
|
||||
public async Task Save(LocalCourse course, LocalCourse? previouslyStoredCourse)
|
||||
{
|
||||
@@ -70,7 +64,7 @@ public class MarkdownCourseSaver
|
||||
{
|
||||
var markdownPath = quizzesDirectory + "/" + quiz.Name + ".md"; ;
|
||||
var quizMarkdown = quiz.ToMarkdown();
|
||||
logger.Log("saving quiz " + markdownPath);
|
||||
_logger.Log("saving quiz " + markdownPath);
|
||||
await File.WriteAllTextAsync(markdownPath, quizMarkdown);
|
||||
}
|
||||
}
|
||||
@@ -94,7 +88,7 @@ public class MarkdownCourseSaver
|
||||
|
||||
foreach (var file in filesToDelete)
|
||||
{
|
||||
logger.Log($"removing old quiz, it has probably been renamed {file}");
|
||||
_logger.Log($"removing old quiz, it has probably been renamed {file}");
|
||||
File.Delete(file);
|
||||
}
|
||||
|
||||
@@ -117,7 +111,7 @@ public class MarkdownCourseSaver
|
||||
var assignmentMarkdown = assignment.ToMarkdown();
|
||||
|
||||
var filePath = assignmentsDirectory + "/" + assignment.Name + ".md";
|
||||
logger.Log("saving assignment " + filePath);
|
||||
_logger.Log("saving assignment " + filePath);
|
||||
await File.WriteAllTextAsync(filePath, assignmentMarkdown);
|
||||
}
|
||||
}
|
||||
@@ -141,9 +135,9 @@ public class MarkdownCourseSaver
|
||||
|
||||
foreach (var file in filesToDelete)
|
||||
{
|
||||
logger.Log($"removing old assignment, it has probably been renamed {file}");
|
||||
_logger.Log($"removing old assignment, it has probably been renamed {file}");
|
||||
File.Delete(file);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user