fix: Create destination directory if not exist
This commit is contained in:
parent
9bc5bd0308
commit
a4608d4a74
1 changed files with 10 additions and 0 deletions
10
Logger.cs
10
Logger.cs
|
|
@ -34,6 +34,8 @@ public class Logger : ILogger
|
||||||
/// <returns>A bool stating if the logger was started</returns>
|
/// <returns>A bool stating if the logger was started</returns>
|
||||||
public static Logger StartLogger(string filePath = "", LogLevel level = LogLevel.DEBUG, DateTime cleanUpBefore = new DateTime(), bool ThrowOnFailedDeletion = false)
|
public static Logger StartLogger(string filePath = "", LogLevel level = LogLevel.DEBUG, DateTime cleanUpBefore = new DateTime(), bool ThrowOnFailedDeletion = false)
|
||||||
{
|
{
|
||||||
|
filePath = filePath.Replace("\\", "/");
|
||||||
|
|
||||||
var handler = new Logger();
|
var handler = new Logger();
|
||||||
handler._provider = new(handler);
|
handler._provider = new(handler);
|
||||||
|
|
||||||
|
|
@ -42,6 +44,14 @@ public class Logger : ILogger
|
||||||
|
|
||||||
if (filePath is not "")
|
if (filePath is not "")
|
||||||
{
|
{
|
||||||
|
if (filePath.Contains('/'))
|
||||||
|
{
|
||||||
|
var dirPath = filePath[..filePath.LastIndexOf('/')];
|
||||||
|
|
||||||
|
if (!Directory.Exists(dirPath))
|
||||||
|
Directory.CreateDirectory(dirPath);
|
||||||
|
}
|
||||||
|
|
||||||
handler.FileName = filePath;
|
handler.FileName = filePath;
|
||||||
handler.OpenedFile = File.Open(handler.FileName, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.Read);
|
handler.OpenedFile = File.Open(handler.FileName, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.Read);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue