Skip to content

Commit

Permalink
Allow to share logs in read mode (#240)
Browse files Browse the repository at this point in the history
* Allow to share logs in read mode

* Catch exception

* Update Logger.cs

* format

format

Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com>
  • Loading branch information
shargon and superboyiii authored May 12, 2020
1 parent 779a0b7 commit 3dcd2bd
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/SystemLog/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,19 @@ void ILogPlugin.Log(string source, LogLevel level, object message)
StringBuilder sb = new StringBuilder(source);
foreach (char c in GetInvalidFileNameChars())
sb.Replace(c, '-');

var path = Combine(Settings.Default.Path, sb.ToString());
Directory.CreateDirectory(path);
path = Combine(path, $"{now:yyyy-MM-dd}.log");
File.AppendAllLines(path, new[] { $"[{level}]{log}" });
try
{
File.AppendAllLines(path, new[] { $"[{level}]{log}" });
}
catch (IOException)
{
Console.WriteLine("Error writing the log file: " + path);

}
}
}
}
Expand Down

0 comments on commit 3dcd2bd

Please sign in to comment.