Ejemplo n.º 1
0
        static public void FormatByLevel(ref string input, LOGLEVEL LogLevel)
        {
            switch ((LOGLEVEL)LogLevel)
            {
            case LOGLEVEL.INFO:
                input = "[INFO]" + input;
                break;

            case LOGLEVEL.FLOW:
                input = "[FLOW]" + input;
                break;

            case LOGLEVEL.NET:
                input = "[NET]" + input;
                break;

            case LOGLEVEL.WARNING:
                input = "[WARNING]" + input;
                break;

            case LOGLEVEL.ERROR:
                input = "[ERROR]" + input;
                break;

            default:
                break;
            }
        }
Ejemplo n.º 2
0
        public void PrintConsole(LOGLEVEL lv, string msg)
        {
            if (lv >= GLOBAL_LOGLEVEL)
            {
                switch (lv)
                {
                case LOGLEVEL.DEBUG:
                    msg = "[DEBUG]" + msg;
                    break;

                case LOGLEVEL.INFO:
                    msg = "[INFO]" + msg;
                    break;

                case LOGLEVEL.WARN:
                    msg = "[WARN]" + msg;
                    break;

                case LOGLEVEL.ERROR:
                    msg = "[ERROR]" + msg;
                    break;
                }
                Console.WriteLine(msg);
            }
        }
Ejemplo n.º 3
0
 private static void Add(LOGLEVEL logLevel, string tag, string message)
 {
     if (!(LogEvent is null)) // Don't call if we haven't registered any events (in MovieLibTests)
     {
         LogEvent(logLevel, tag, message);
     }
 }
Ejemplo n.º 4
0
 private static void Logger_LogEventLogFile(LOGLEVEL logLevel, string tag, string message)
 {
     using (StreamWriter writer = new StreamWriter(LOG_FILE, true))
     {
         writer.WriteLine(GetLogFormattedString(logLevel, tag, message));
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Logs the message at the given level
 /// </summary>
 /// <param name="_logMessage">Message to log</param>
 /// <param name="_level">Level to log</param>
 internal static void Debug(String _logMessage, LOGLEVEL _level)
 {
     if (_level >= CURRENT_LEVEL)
       {
     switch (_level)
     {
       case LOGLEVEL.Debug:
     //debug log processing
     Console.WriteLine(_logMessage);
     break;
       case LOGLEVEL.Info:
     //debug log processing
     Console.WriteLine(_logMessage);
     break;
       case LOGLEVEL.Warn:
     //debug log processing
     Console.WriteLine(_logMessage);
     break;
       case LOGLEVEL.Error:
     //debug log processing
     Console.WriteLine(_logMessage);
     break;
       case LOGLEVEL.Fatal:
     //debug log processing
     Console.WriteLine(_logMessage);
     break;
     }
       }
 }
Ejemplo n.º 6
0
        private void SetConfig()
        {
            try
            {
                string p1 = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                Console.WriteLine(p1);
                string path = Path.Combine(p1, "App.config");
                if (File.Exists(path) == false)
                {
                    throw new FileNotFoundException("App.config file not found");
                }

                m_config = this.OpenConfiguration(path);
                string value = m_config.AppSettings.Settings["LogLevel"].Value;

                LOGLEVEL level;
                if (Enum.TryParse <LOGLEVEL>(value.ToUpper(), out level))
                {
                    if (e_logLevel.Equals(level) == false)
                    {
                        NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(m_target, GetLogLevel(level));
                        e_logLevel = level;
                    }
                }
                else
                {
                    throw new Exception("Fail to Set Log Level");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 7
0
        public void LogWrite(string msg, LOGLEVEL level = LOGLEVEL.INFO)
        {
            switch (level)
            {
            case LOGLEVEL.NONE:
                break;

            case LOGLEVEL.TRACE:
                m_logger.Trace(msg);
                break;

            case LOGLEVEL.DEBUG:
                m_logger.Debug(msg);
                break;

            case LOGLEVEL.INFO:
                m_logger.Info(msg);
                break;

            case LOGLEVEL.WARN:
                m_logger.Warn(msg);
                break;

            case LOGLEVEL.ERROR:
                m_logger.Error(msg);
                break;

            case LOGLEVEL.FATAL:
                m_logger.Fatal(msg);
                break;

            default:
                break;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Logs the message at the given level
        /// </summary>
        /// <param name="_logMessage">Message to log</param>
        /// <param name="_level">Level to log</param>
        internal static void Debug(String _logMessage, LOGLEVEL _level)
        {
            if (_level >= CURRENT_LEVEL)
            {
                switch (_level)
                {
                case LOGLEVEL.Debug:
                    //debug log processing
                    Console.WriteLine(_logMessage);
                    break;

                case LOGLEVEL.Info:
                    //debug log processing
                    Console.WriteLine(_logMessage);
                    break;

                case LOGLEVEL.Warn:
                    //debug log processing
                    Console.WriteLine(_logMessage);
                    break;

                case LOGLEVEL.Error:
                    //debug log processing
                    Console.WriteLine(_logMessage);
                    break;

                case LOGLEVEL.Fatal:
                    //debug log processing
                    Console.WriteLine(_logMessage);
                    break;
                }
            }
        }
Ejemplo n.º 9
0
 private void DoLog(string str, LOGLEVEL level)
 {
     if (level >= logLevel)
     {
         InternalDoLog(string.Format("【{0}】{1}", DateTime.Now, str));
     }
 }
Ejemplo n.º 10
0
        //==================
        public void Print(LOGLEVEL lv, string msg)
        {
            if (lv >= GLOBAL_LOGLEVEL && msg.Length > 0)
            {
                switch (lv)
                {
                case LOGLEVEL.DEBUG:
                    msg = "[DEBUG]" + msg;
                    break;

                case LOGLEVEL.INFO:
                    msg = "[INFO]" + msg;
                    break;

                case LOGLEVEL.WARN:
                    msg = "[WARN]" + msg;
                    break;

                case LOGLEVEL.ERROR:
                    msg = "[ERROR]" + msg;
                    break;
                }
                msg = msg + '\n';
                LogWindow.Dispatcher.Invoke(new Action(() =>
                {
                    LogWindow.Text = LogWindow.Text + msg;
                    LogWindow.ScrollToEnd();
                }));
            }
        }
Ejemplo n.º 11
0
        int getTypeId(RealStatePtr L, Type type, out bool is_first, LOGLEVEL log_level = LOGLEVEL.WARN)
        {
            int type_id;
            is_first = false;
            if (!typeIdMap.TryGetValue(type, out type_id)) // no reference
            {
                if (type.IsArray)
                {
                    if (common_array_meta == -1) throw new Exception("Fatal Exception! Array Metatable not inited!");
                    return common_array_meta;
                }
                if (typeof(MulticastDelegate).IsAssignableFrom(type))
                {
                    if (common_delegate_meta == -1) throw new Exception("Fatal Exception! Delegate Metatable not inited!");
                    return common_delegate_meta;
                }

                is_first = true;
                Type alias_type = null;
                aliasCfg.TryGetValue(type, out alias_type);
                LuaAPI.luaL_getmetatable(L, alias_type == null ? type.FullName : alias_type.FullName);

                if (LuaAPI.lua_isnil(L, -1)) //no meta yet, try to use reflection meta
                {
                    LuaAPI.lua_pop(L, 1);

                    if (TryDelayWrapLoader(L, alias_type == null ? type : alias_type))
                    {
                        LuaAPI.luaL_getmetatable(L, alias_type == null ? type.FullName : alias_type.FullName);
                    }
                    else
                    {
                        throw new Exception("Fatal: can not load metatable of type:" + type);
                    }
                }

                //循环依赖,自身依赖自己的class,比如有个自身类型的静态readonly对象。
                if (typeIdMap.TryGetValue(type, out type_id))
                {
                    LuaAPI.lua_pop(L, 1);
                }
                else
                {
                    LuaAPI.lua_pushvalue(L, -1);
                    type_id = LuaAPI.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);
                    LuaAPI.lua_pushnumber(L, type_id);
                    LuaAPI.xlua_rawseti(L, -2, 1);
                    LuaAPI.lua_pop(L, 1);

                    if (type.IsValueType)
                    {
                        typeMap.Add(type_id, type);
                    }

                    typeIdMap.Add(type, type_id);
                }
            }
            return type_id;
        }
Ejemplo n.º 12
0
 /// <summary>
 /// 获得日志级别
 /// </summary>
 /// <param name="level"></param>
 /// <returns></returns>
 private static string getLogLevelDesp(LOGLEVEL level)
 {
     if ((uint)level > (uint)(LOGLEVEL.LOGSUCCESS))
     {
         return "Unknow Level";
     }
     return LEVELSTRING[(uint)level];
 }
Ejemplo n.º 13
0
 protected AsynEventSubscriber()
 {
     RecvExpire  = 2000;
     MsgEncoding = Encoding.ASCII;
     IsDetectServerSwitchover = false;
     EventIdleTime            = 30;
     LogLevel = LOGLEVEL.DEBUG;
 }
Ejemplo n.º 14
0
        protected void Log(LOGLEVEL level, string info)
        {
            if (level < LogLevel)
            {
                return;
            }

            if (LogInfo != null)
            {
                LogInfo(this, new LogArgs(level, info));
            }
        }
Ejemplo n.º 15
0
        public CCBConfig()
        {
            m_filename    = MakeFileName(m_version);
            m_tmpFilename = MakeTempFileName(m_version);
            m_docLocation = null;
            m_docFullPath = null;
#if DEBUG
            m_loglevel = LOGLEVEL.LOGDEBUG;
#else
            m_loglevel = LOGLEVEL.LOGERROR;
#endif
        }
Ejemplo n.º 16
0
        public static void SetModuleLevel(string module, LOGLEVEL level)
        {
            LOGLEVEL current;

            Init();

            if (moduleLogStatus.TryGetValue(module, out current))
            {
                moduleLogStatus[module] = level;
            }
            else
            {
                AddModule(module, level);
            }
        }
Ejemplo n.º 17
0
        private static void Logger_LogEventConsole(LOGLEVEL logLevel, string tag, string message)
        {
            switch (logLevel)   // Set console color based on loglevel
            {
            case LOGLEVEL.ERROR:
            case LOGLEVEL.FATAL:
                Console.ForegroundColor = ConsoleColor.DarkRed;
                break;

            default:
                Console.ForegroundColor = ConsoleColor.DarkBlue;
                break;
            }

            Console.WriteLine(GetLogFormattedString(logLevel, tag, message));
            Console.ForegroundColor = ConsoleColor.White;   // restore console color
        }
Ejemplo n.º 18
0
        //Editor下输出到Console和文件中
        //外网输出 error, flow, net. 崩溃时看能否上报(暂不做)
        //外网这里要把error上报(暂不做)
        static public void WriteToAll(string strContent, LOGLEVEL LogLevel)
        {
            FormatByLevel(ref strContent, LogLevel);

            //尝试输出到命令行
            if (LineConsole.Instance != null)
            {
                LineConsole.Instance.sendToConsoleAtom(strContent);
            }

            WriteToUnityDebugConsole(strContent, LogLevel);

            //输出到文件
#if UNITY_EDITOR
            Log.FileWrite(strContent);
#endif
        }
Ejemplo n.º 19
0
        public static void Message(string message, string module = "Unkown", LOGLEVEL messageLevel = LOGLEVEL.NORMAL)
        {
#if !NOLOGGING
            Init();

            LOGLEVEL moduleLevel;

            if (!moduleLogStatus.TryGetValue(module, out moduleLevel))
            {
                moduleLevel = AssitantDirector.Instance.DefaultLogLevel;
            }

            if (messageLevel <= moduleLevel)
            {
                Debug.Log(module + ": " + message);
            }
#endif
        }
Ejemplo n.º 20
0
        private LogManager()
        {
            e_logLevel = LOGLEVEL.NONE;

            m_projectName    = System.Reflection.Assembly.GetEntryAssembly().GetName().Name;
            m_projectVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
            m_configPath     = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), m_projectName, m_projectVersion);

            m_target                  = new FileTarget();
            m_target.Layout           = "${processid} ${longdate} [${level}]   ${message}${exception:format=ToString}";
            m_target.FileName         = "${basedir}/logs/${shortdate} log.txt";
            m_target.ArchiveAboveSize = 10000 * 1024; // archive files greater than 10 MB
            m_target.ConcurrentWrites = true;

            NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(m_target, LogLevel.Debug);
            m_logger = NLog.LogManager.GetLogger("CavuLogger");

            SetConfig();
        }
Ejemplo n.º 21
0
 public CCBLogger(string logfilepath, LOGLEVEL loglevel)
 {
     m_loglevel = loglevel;
     try
     {
         m_writer           = new StreamWriter(logfilepath);
         m_writer.AutoFlush = true;
     }
     catch (IOException ioex)
     {
         System.Diagnostics.Debug.WriteLine("Could not open log file " + logfilepath);
         System.Diagnostics.Debug.WriteLine("  Error: " + ioex.Message);
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Error when opening log file " + logfilepath);
         System.Diagnostics.Debug.WriteLine("  Error: " + ex.Message);
     }
 }
Ejemplo n.º 22
0
        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static int _WriteLog(LOGLEVEL level, string context)
        {
            LOG_PATH = CommonVary.logPath + "\\Log_" + DateTime.Today.ToString("yyyyMMdd") + ".txt";

            string LogLevel = getLogLevelDesp((LOGLEVEL)level);
            context = LOG_HEADER_FORMAT + " " + LogLevel + " :"+ context;
            int rc = CommonVary.RUNNING_OK;
            try
            {
                fileOperation.CreateIfNotExist(LOG_PATH);
                fileOperation.WriteLine(context);

            }
            catch (System.Exception ex)
            {
                MessageBox.Show("日志写入出错:" + context);
                return CommonVary.RUNNNING_WRONG;
            }
            return rc;
        }
Ejemplo n.º 23
0
        public static void Log(string message, LOGLEVEL logLevel)
        {
            //try
            //{
            //    using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
            //    {
            //        string directory = "log";
            //        if(store.GetDirectoryNames(directory).Length==0)
            //        {
            //            store.CreateDirectory(directory);
            //        }

            //        string filename = string.Format(@"{0}\{1}.log",directory, DateTime.Now.ToString("yyyyMMdd"));
            //        using (Stream stream = new IsolatedStorageFileStream(filename, FileMode.Append, FileAccess.Write, store))
            //        {
            //            StreamWriter writer = new StreamWriter(stream);
            //            switch (logLevel)
            //            {
            //                case LOGLEVEL.INFO:
            //                    writer.Write(String.Format("{0:u} [INFO] {1}{2}", DateTime.Now, message, Environment.NewLine));
            //                    break;
            //                case LOGLEVEL.WARNING:
            //                    writer.Write(String.Format("{0:u} [WARNING] {1}{2}", DateTime.Now, message, Environment.NewLine));
            //                    break;
            //                case LOGLEVEL.ERROR:
            //                    writer.Write(String.Format("{0:u} [ERROR] {1}{2}", DateTime.Now, message, Environment.NewLine));
            //                    break;
            //                case LOGLEVEL.FATAL:
            //                    writer.Write(String.Format("{0:u} [FATAL] {1}{2}", DateTime.Now, message, Environment.NewLine));
            //                    break;
            //                default:
            //                    break;
            //            }
            //            writer.Close();
            //        }
            //    }
            //}
            //catch (Exception ex)
            //{
            //}
        }
Ejemplo n.º 24
0
        public static void Warning(string message, string module = "Unkown")
        {
#if !NOLOGGING
            Init();

            LOGLEVEL messageLevel = LOGLEVEL.WARNINGS;

            LOGLEVEL moduleLevel;

            if (!moduleLogStatus.TryGetValue(module, out moduleLevel))
            {
                moduleLevel = GetDefaultLevel();
            }

            if (messageLevel <= moduleLevel)
            {
                Debug.LogWarning(module + ": " + message);
                DeusHandler.Instance?.AddLogLine(module + ": " + message);
            }
#endif
        }
Ejemplo n.º 25
0
        public static void Error(string message, string module = "Unkown")
        {
            Init();

            LOGLEVEL messageLevel = LOGLEVEL.ERRORS;

            LOGLEVEL moduleLevel;

            if (!moduleLogStatus.TryGetValue(module, out moduleLevel))
            {
                moduleLevel = AssitantDirector.Instance.DefaultLogLevel;
            }

            if (messageLevel <= moduleLevel)
            {
                Debug.LogError(module + ": " + message);
                if (errorEcho != null)
                {
                    errorEcho(message, module);
                }
            }
        }
Ejemplo n.º 26
0
        public void write(string sLogs, LOGLEVEL logLEVEL = LOGLEVEL.DEBUG)
        {
            try
            {
                Console.WriteLine(sLogs);

                var sLogEntryType = EventLogger.EntryType.ERROR;

                if (logLEVEL == LOGLEVEL.INFO)
                {
                    sLogEntryType = EventLogger.EntryType.INFO;
                }

                try
                {
                    EventLogger.write(sLogs, sLogEntryType);
                }
                catch (Exception error)
                {
                    Console.WriteLine(error.Message);
                };

                try
                {
                    if (this.log_level.Contains(logLEVEL.ToString()))
                    {
                        this.push(sLogs, logLEVEL);
                    }
                }
                catch (Exception error)
                {
                    Console.WriteLine(error.Message);
                };
            }
            catch (Exception error)
            {
                Console.WriteLine(error.Message);
            }
        }
Ejemplo n.º 27
0
        public static void Error(string message, string module = "Unkown")
        {
            Init();

            LOGLEVEL messageLevel = LOGLEVEL.ERRORS;

            LOGLEVEL moduleLevel;

            if (!moduleLogStatus.TryGetValue(module, out moduleLevel))
            {
                moduleLevel = GetDefaultLevel();
            }

            if (messageLevel <= moduleLevel)
            {
                Debug.LogError(module + ": " + message);
                DeusHandler.Instance?.AddLogLine(module + ": " + message);
                if (errorEcho != null)
                {
                    errorEcho(message, module);
                }
            }
        }
Ejemplo n.º 28
0
        static public void WriteToUnityDebugConsole(string strContent, LOGLEVEL LogLevel)
        {
            //输出到debug命令台
            if (LogLevel == LOGLEVEL.ERROR)
            {
#if UNITY_EDITOR
                Log.ConsoleWriteError(strContent);
#else
                YLMobile.Debug.Error(strContent);
#endif
            }
            else if (LogLevel == LOGLEVEL.WARNING)
            {
#if UNITY_EDITOR
                Log.ConsoleWriteWarning(strContent);
#endif
            }
            else
            {
#if UNITY_EDITOR
                Log.ConsoleWrite(strContent);
#endif
            }
        }
Ejemplo n.º 29
0
 public static void setLogLevel(LOGLEVEL level)
 {
     Logger.level = level;
 }
Ejemplo n.º 30
0
 public static void setLogLevel(LOGLEVEL level)
 {
     Logger.level = level;
 }
Ejemplo n.º 31
0
    public static void Write(LOGLEVEL logLevel, string logEntry, DateTime eventTime)

    {
        System.Diagnostics.Debug.WriteLine(eventTime.ToShortDateString() + " " + eventTime.ToShortTimeString() + " " + logEntry);
    }
Ejemplo n.º 32
0
    public static void Write(LOGLEVEL logLevel, string logEntry)

    {
        System.Diagnostics.Debug.WriteLine(logEntry);
    }
Ejemplo n.º 33
0
 public LogArgs(LOGLEVEL level, string info)
 {
     Level = level;
     Info  = info;
 }
Ejemplo n.º 34
0
 public LogLevel(LOGLEVEL level)
 {
     Level = level;
 }
Ejemplo n.º 35
0
        /// <summary>
        /// Returns a formatted Log string.
        /// Example: [27/05:45][WARN][HTTP] Connection Refused
        /// </summary>
        private static string GetLogFormattedString(LOGLEVEL logLevel, string tag, string message)
        {
            string timeString = DateTime.Now.ToString("dd/HH:mm");

            return($"[{timeString}][{logLevel}][{tag}] {message}");
        }