| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- 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();
- }
- }
- }
|