Improve file logging

This commit is contained in:
jvyden 2022-05-01 18:40:41 -04:00
commit 1402bcfd65
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278

View file

@ -12,14 +12,12 @@ public class LighthouseFileLogger : ILogger
{ {
FileHelper.EnsureDirectoryCreated(logsDirectory); FileHelper.EnsureDirectoryCreated(logsDirectory);
string channel = string.IsNullOrEmpty(line.Area) ? "" : $"[{line.Area}] "; string contentFile = $"[{line.Level}] <{line.Trace.Name}:{line.Trace.Section}> {line.Message}\n";
string contentAll = $"[{line.Area}:{line.Level}] <{line.Trace.Name}:{line.Trace.Section}> {line.Message}\n";
string contentFile = $"{channel}{line.Message}\n";
string contentAll = $"[{$"{line.Level} {channel}".TrimEnd()}] {line.Message}\n";
try try
{ {
File.AppendAllText(Path.Combine(logsDirectory, line.Level + ".log"), contentFile); File.AppendAllText(Path.Combine(logsDirectory, line.Area + ".log"), contentFile);
File.AppendAllText(Path.Combine(logsDirectory, "all.log"), contentAll); File.AppendAllText(Path.Combine(logsDirectory, "all.log"), contentAll);
} }
catch(IOException) {} // windows, ya goofed catch(IOException) {} // windows, ya goofed