mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-06-04 07:02:28 +00:00
Ensure that log file names do not use invalid filename characters.
This commit is contained in:
parent
455341ffeb
commit
97fe7b07cd
2 changed files with 22 additions and 1 deletions
20
ProjectLighthouse/Helpers/Extensions/StringExtensions.cs
Normal file
20
ProjectLighthouse/Helpers/Extensions/StringExtensions.cs
Normal file
|
@ -0,0 +1,20 @@
|
|||
using System.IO;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Helpers.Extensions
|
||||
{
|
||||
public static class StringExtensions
|
||||
{
|
||||
public static string ToFileName(this string text)
|
||||
{
|
||||
char[] invalidPathChars = Path.GetInvalidFileNameChars();
|
||||
string path = text;
|
||||
|
||||
foreach (char c in invalidPathChars)
|
||||
{
|
||||
path = path.Replace(c.ToString(), "");
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.IO;
|
||||
using Kettu;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Logging
|
||||
{
|
||||
|
@ -18,7 +19,7 @@ namespace LBPUnion.ProjectLighthouse.Logging
|
|||
string contentFile = $"{channel}{line.LineData}\n";
|
||||
string contentAll = $"[{$"{line.LoggerLevel.Name} {channel}".TrimEnd()}] {line.LineData}\n";
|
||||
|
||||
File.AppendAllText(Path.Combine(logsDirectory, line.LoggerLevel.Name + ".log"), contentFile);
|
||||
File.AppendAllText(Path.Combine(logsDirectory, line.LoggerLevel.Name.ToFileName() + ".log"), contentFile);
|
||||
File.AppendAllText(Path.Combine(logsDirectory, "all.log"), contentAll);
|
||||
}
|
||||
public override bool AllowMultiple => false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue