123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- using System;
- using System.Text;
- using Core.Utility;
- #if COMBAT_SERVER
- using NLog;
- #endif
- #if !COMBAT_SERVER
- using UnityEngine;
- #endif
- using Object = System.Object;
- namespace Fort23.UTool
- {
- public class LogTool
- {
- public static ILogSend LogSend;
- public static string ColorForGreen = "green";
- public static string ColorForOrange = "orange";
- public static string ColorForRed = "red";
- #if COMBAT_SERVER
- public static NLog.Logger logger
- {
- get
- {
- if (_logger == null)
- {
- _logger = NLog.LogManager.GetCurrentClassLogger();
- }
- return _logger;
- }
- }
- private static NLog.Logger _logger;
- #endif
- #if UNITY_EDITOR
- public static bool IsDebug = true;
- #else
- #if COMBAT_SERVER
- public static bool IsDebug = true;
- #else
- public static bool IsDebug = false;
- #endif
- #endif
- private static StringBuilder ColorLog(object str, string color)
- {
- string colorFormat = color;
- StringBuilder sb = new StringBuilder();
- sb.AppendFormat("<color={1}>[{0}]</color>", str, colorFormat);
- return sb;
- }
- public static void Log(object msg)
- {
- if (!IsDebug)
- {
- return;
- }
- #if !COMBAT_SERVER
- Debug.Log(ColorLog(msg, ColorForGreen));
- #elif COMBAT_SERVER
- logger.Log(LogLevel.Info, msg);
- #endif
- }
- public static void Log(string msg)
- {
- if (!IsDebug)
- {
- return;
- }
- #if !COMBAT_SERVER
- Debug.Log(ColorLog(msg, ColorForGreen));
- #elif COMBAT_SERVER
- logger.Log(LogLevel.Info, msg);
- // logger.Log(LogLevel.Info, msg);
- #endif
- }
- public static void Warning(string msg)
- {
- #if!COMBAT_SERVER
- Debug.LogWarning(ColorLog(msg, ColorForOrange));
- #elif COMBAT_SERVER
- logger.Log(LogLevel.Warn, msg);
- #endif
- }
- /// <summary>
- /// 错误是任何情况下都会打印。
- /// </summary>
- /// <param name="msg"></param>
- public static void Error(string msg)
- {
- // System.Diagnostics.StackTrace stackTrace= new System.Diagnostics.StackTrace();
- LogSend?.SendError(msg);
- #if !COMBAT_SERVER
- Debug.LogError(ColorLog(msg, ColorForRed));
- // Debug.LogError(msg);
- #elif COMBAT_SERVER
- logger.Error(msg);
- #endif
- }
- /// <summary>
- /// 错误是任何情况下都会打印。
- /// </summary>
- /// <param name="e"></param>
- public static void Error(Exception e)
- {
- LogSend?.SendException(e);
- #if !COMBAT_SERVER
- Exception(e);
- #elif COMBAT_SERVER
- logger.Error(e);
- #endif
- }
- public static void Exception(Exception e)
- {
- LogSend?.SendException(e);
- #if !COMBAT_SERVER
- Debug.LogException(e);
- #elif COMBAT_SERVER
- Console.WriteLine(e);
- logger.Error(e);
- #endif
- }
- #if UNITY_EDITOR
- /// <summary>
- /// 暂停游戏
- /// </summary>
- public static void Paused()
- {
- UnityEditor.EditorApplication.isPaused = true;
- }
- #endif
- }
- }
|