| using System.IO; |
| using log4net; |
| using UnityEngine; |
| |
| namespace Config |
| { |
| public static class LoggerControl |
| { |
| private static ILog log = LogManager.GetLogger("FileLogger"); |
| |
| public static void Init() |
| { |
| Application.logMessageReceived += OnLogMessageReceived; |
| |
| |
| FileInfo file = new FileInfo(Application.streamingAssetsPath+ "/Configs/Log/log4net.xml"); |
| GlobalContext.Properties["ApplicationLogPath"] = Path.Combine(Directory.GetCurrentDirectory(), "Log"); |
| Debug.Log(GlobalContext.Properties["ApplicationLogPath"]); |
| GlobalContext.Properties["LogFileName"] = "log"; |
| log4net.Config.XmlConfigurator.ConfigureAndWatch(file); |
| } |
| |
| public static void CloseLog() |
| { |
| log.Logger.Repository.Shutdown(); |
| } |
| |
| public static void WriteLog(string text) |
| { |
| log.Info(text); |
| } |
| |
| private static void OnLogMessageReceived(string condition, string stackTrace, LogType type) |
| { |
| switch (type) |
| { |
| case LogType.Error: |
| log.ErrorFormat("{0}\r\n{1}", condition, stackTrace.Replace("\n", "\r\n")); |
| break; |
| case LogType.Assert: |
| log.DebugFormat("{0}\r\n{1}", condition, stackTrace.Replace("\n", "\r\n")); |
| break; |
| case LogType.Exception: |
| log.FatalFormat("{0}\r\n{1}", condition, stackTrace.Replace("\n", "\r\n")); |
| break; |
| case LogType.Warning: |
| log.WarnFormat("{0}\r\n{1}", condition, stackTrace.Replace("\n", "\r\n")); |
| break; |
| default: |
| log.Info(condition); |
| break; |
| } |
| } |
| } |
| } |