using System; using System.IO; using System.Runtime.CompilerServices; using System.Text; using UnityEngine; namespace ET { public class FileLogger: ILog { private readonly StreamWriter stream; public FileLogger(string filepath = null) { if (filepath == null) { #if UNITY_EDITOR || UNITY_STANDALONE filepath = "./"; #elif UNITY_ANDROID filepath = Application.persistentDataPath; #endif filepath = Path.Combine(filepath, "Log.txt"); } FileStream fs = File.Open(filepath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite); fs.Seek(0, SeekOrigin.End); this.stream = new StreamWriter(fs, Encoding.UTF8); //this.stream = new StreamWriter(File.Open(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)); this.stream.AutoFlush = true; } public void Trace(string message) { this.stream.WriteLine(message); this.stream.Flush(); } public void Warning(string message) { this.stream.WriteLine(message); this.stream.Flush(); } public void Info(string message) { this.stream.WriteLine(message); this.stream.Flush(); } public void Debug(string message) { this.stream.WriteLine(message); this.stream.Flush(); } public void Error(string message) { this.stream.WriteLine(message); this.stream.Flush(); } public void Trace(string message, params object[] args) { this.stream.WriteLine(message, args); this.stream.Flush(); } public void Warning(string message, params object[] args) { this.stream.WriteLine(message, args); this.stream.Flush(); } public void Info(string message, params object[] args) { this.stream.WriteLine(message, args); this.stream.Flush(); } public void Debug(string message, params object[] args) { this.stream.WriteLine(message, args); this.stream.Flush(); } public void Error(string message, params object[] args) { this.stream.WriteLine(message, args); this.stream.Flush(); } public void Fatal(string message, params object[] args) { this.stream.WriteLine(message, args); this.stream.Flush(); } } }