33 lines
		
	
	
		
			831 B
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			831 B
		
	
	
	
		
			C#
		
	
	
	
	
	
using System;
 | 
						|
using System.IO;
 | 
						|
 | 
						|
namespace Engine.Core.Debug;
 | 
						|
 | 
						|
public class FileLogger : LoggerBase
 | 
						|
{
 | 
						|
    public readonly string FilePath;
 | 
						|
 | 
						|
    protected override void Write(string message)
 | 
						|
    {
 | 
						|
        File.AppendAllTextAsync(FilePath, $"{message}{Environment.NewLine}");
 | 
						|
    }
 | 
						|
 | 
						|
    public FileLogger(string filePath)
 | 
						|
    {
 | 
						|
        if (!filePath.EndsWith(".log"))
 | 
						|
            filePath += ".log";
 | 
						|
 | 
						|
        FilePath = filePath;
 | 
						|
 | 
						|
        bool isRelativePath = Path.GetFullPath(filePath).CompareTo(filePath) != 0;
 | 
						|
 | 
						|
        if (isRelativePath)
 | 
						|
            FilePath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filePath));
 | 
						|
 | 
						|
        if (Path.GetDirectoryName(FilePath) is string directoryPath)
 | 
						|
            Directory.CreateDirectory(directoryPath);
 | 
						|
 | 
						|
        File.Open(FilePath, FileMode.Create).Close();
 | 
						|
    }
 | 
						|
}
 |