diff --git a/ProjectLighthouse/Helpers/Extensions/StringExtensions.cs b/ProjectLighthouse/Helpers/Extensions/StringExtensions.cs new file mode 100644 index 00000000..4ed898e9 --- /dev/null +++ b/ProjectLighthouse/Helpers/Extensions/StringExtensions.cs @@ -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; + } + } +} \ No newline at end of file diff --git a/ProjectLighthouse/Logging/LighthouseFileLogger.cs b/ProjectLighthouse/Logging/LighthouseFileLogger.cs index 8dbfea54..31879a69 100644 --- a/ProjectLighthouse/Logging/LighthouseFileLogger.cs +++ b/ProjectLighthouse/Logging/LighthouseFileLogger.cs @@ -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;