Beispiel #1
0
 public void log(object caller, string message, ELogLevel level)
 {
     DateTime now = DateTime.Now;
     string line = level.ToString() + ": (" + now.ToLongTimeString() + " " + now.ToLongDateString() + ") [" + caller.ToString() + "] ~" + message;
     Llog.Add(line);
     loggedLevel.Add(level);
     writeLogToFile();
     //displayLine();
 }
Beispiel #2
0
        public void log(object caller, string message, ELogLevel level)
        {
            DateTime now  = DateTime.Now;
            string   line = level.ToString() + ": (" + now.ToLongTimeString() + " " + now.ToLongDateString() + ") [" + caller.ToString() + "] ~" + message;

            Llog.Add(line);
            loggedLevel.Add(level);
            writeLogToFile();
            //displayLine();
        }
        public static void Add(ELogLevel level, string message, params object[] args)
        {
            if (string.IsNullOrEmpty(message))
            {
                message = "NULL";
            }

            var fMessage = string.Format(DateTime.Now.ToString(CultureInfo.InvariantCulture) + ": " + message, args);

            if (EnableDebugger)
            {
                Debugger.Log((int)level, level.ToString(), fMessage);
            }

            if (EnableTrace)
            {
                Trace.WriteLine(fMessage, level.ToString());
            }
        }
Beispiel #4
0
        /*  función estática Log(object, string, Level) => void
         *      Retransmite un mensaje a través del logging de la aplicación
         *  @param component : componente llamando a la función, o null si es éste propio programa
         *  @param message : mensaje a retransmitir
         *  @param level : nivel de severidad del mensaje
         */
        public static void Log(object component, string message, ELogLevel level)
        {
            if (component == null)
            {
                message = $"Program - {message}";
            }
            else if (component is Packager)
            {
                message = $"Packager - {message}";
            }
            else if (component is Parser)
            {
                message = $"Parser - {message}";
            }
            else if (component is Provider)
            {
                message = $"Provider - {message}";
            }
            else if (component is Mapper)
            {
                message = $"Mapper - {message}";
            }
            switch (level)
            {
            case ELogLevel.DEBUG:
                _logger.Debug(message);
                break;

            case ELogLevel.INFO:
                _logger.Info(message);
                break;

            case ELogLevel.WARN:
                _logger.Warn(message);
                break;

            case ELogLevel.ERROR:
                _logger.Error(message);
                break;

            case ELogLevel.FATAL:
                _logger.Fatal(message);
                break;

            default:
                Console.WriteLine("Directiva " + level.ToString() + " no reconocida");
                break;
            }
        }
Beispiel #5
0
        public void WriteLog(string message, ELogLevel logLevel)
        {
            string fileName = System.IO.Path.Combine(_path, $"Logs-{DateTime.Now.ToCNZone().ToString("yyyy-MM-dd")}");

            using (var sw = File.AppendText(fileName))
            {
                string startStr = $"[Start Level:{logLevel.ToString()} Time:{DateTime.Now.ToCNZone().ToString("yyyy-MM-dd HH:mm:ss,fff")}]";
                sw.WriteLine(startStr);
                sw.WriteLine(message);
                string endStr = "[End]";
                sw.WriteLine(endStr);
                sw.WriteLine();
                sw.Flush();
            }
        }
Beispiel #6
0
        public void Log(ELogLevel level, string tag, string message)
        {
#if DEBUG
            Debug.WriteLine(level.ToString() + " " + tag + " " + message);
#endif
            try
            {
                this.OnAppendLog(level, tag, message);
                if ((this._LogLevel & level) == level)
                {
                    if (this._DefaultHandler != null)
                    {
                        this._DefaultHandler.Log(level, tag, message);
                    }
                }
            }
            catch { }
        }
Beispiel #7
0
    private void PackMessage(LogMessage msg, StringBuilder builder)
    {
        System.DateTime time = msg.time;

        string curTime = string.Format("{0:00}-{1:00} {2:00}:{3:00}:{4:00}.{5:000}",
                                       time.Month, time.Day, time.Hour, time.Minute, time.Second, time.Millisecond);

        ELogLevel level  = msg.level;
        string    prefix = string.Format("{0} {1} {2}/{3}: ", cLogPrefix, curTime, level.ToString()[0], msg.tag);

        string stack = null;

        if (msg.level >= LogConstant.PRINT_STACK_LEVEL && msg.level != ELogLevel.Key)
        {
            stack = msg.stackStr;
        }

        StringBuilder stringBuilder = TransInLine(prefix, msg.content, stack, builder);

        msg.packedContent = stringBuilder.ToString();
    }
Beispiel #8
0
    public static void Log(ELogLevel level, ELogTag tag, string content, string stack)
    {
        CLogSys logSys = CGameRoot.GetGameSystem <CLogSys>();

        if (logSys == null)
        {
            return;
        }
        if ((int)level < (int)logSys.mSelfLogLevel)
        {
            return;
        }

        //if (FightScene.mInstance != null && FightScene.mInstance.isBattleStart)
        //{
        //    return;
        //}

        #region 重复内容保护
        string sameStr = content.Substring(0, Mathf.Min(20, content.Length));
        if (string.IsNullOrEmpty(mSameLogStr) || mSameLogStr != sameStr)
        {
            mSameLogStr = sameStr;
            mSameLogCnt = 0;
        }
        else
        {
            mSameLogCnt++;
        }
        if (mSameLogCnt > 20)
        {
            return;
        }
        #endregion

#if !UNITY_EDITOR
        if (string.IsNullOrEmpty(stack))
        {
            System.Diagnostics.StackTrace   stackTrace  = new System.Diagnostics.StackTrace(true);
            System.Diagnostics.StackFrame[] stackFrames = stackTrace.GetFrames();
            System.Text.StringBuilder       sb          = new System.Text.StringBuilder();
            for (int i = 0; i < stackFrames.Length; ++i)
            {
                System.Reflection.MethodBase method = stackFrames[i].GetMethod();
                string typeName   = method.DeclaringType.FullName;
                string methodName = method.Name;
                if (typeName == "CLogSys" ||
                    typeName == "UnityEngine.Debug" ||
                    methodName == "CallLogCallback")
                {
                    continue;
                }

                sb.AppendFormat("{0}:{1}\n", typeName, methodName);
            }
            stack = sb.ToString();
        }

        char[] contentInLine;
        int    contentIdx;
        TransInLine(content, out contentInLine, out contentIdx);

        char[] stackInLine;
        int    stackIdx;
        TransInLine(stack, out stackInLine, out stackIdx);

        System.DateTime now     = System.DateTime.Now;
        string          curTime = string.Format("{0:00}{1:00}{2:00}{3:00}{4:00}", now.Month, now.Day, now.Hour, now.Minute, now.Second);
        string          logStr  = string.Format("{0}|{1}|{2}|{3}|{4}|{5}", cLogPrefix, curTime, level.ToString()[0], tag,
                                                new string(contentInLine, 0, contentIdx), new string(stackInLine, 0, stackIdx));

        //ELogLevel logLevel = (ResourceSys != null && ResourceSys.RootCfg != null) ? ResourceSys.RootCfg.mLogLevel : ELogLevel.Debug;
        if (mLogPlatform != null)
        {
            mLogPlatform.Log(logStr);
        }

        if (level >= ELogLevel.Error)
        {
            //DCProxy.ReportError(content, logStr);
        }
#else
        if (level == ELogLevel.Warning)
        {
            Debug.LogWarning(content);
        }
        else if (level == ELogLevel.Error)
        {
            Debug.LogError(content);
        }
        else if (level == ELogLevel.Fatal)
        {
            Debug.LogError(content);
        }
        else if (level == ELogLevel.Debug)
        {
            Debug.LogWarning(content);
        }
        else if (level == ELogLevel.Verbose)
        {
            Debug.Log(content);
        }
#endif
    }
Beispiel #9
0
 public static void WriteLine(ELogLevel pLogLevel, string pFormat, params object[] pArgs)
 {
     OnOutput(DateTime.Now.ToString() + " <" + pLogLevel.ToString() + "> " + string.Format(pFormat, pArgs));
 }
Beispiel #10
0
 public static void updateLog(string txt, ELogLevel level, ELogType whom)
 {
     if (level == ELogLevel.Debug && (whom != ELogType.SpeechRecog && whom != ELogType.Net)) return;
     if (Form1.server.txtLog.InvokeRequired)
     {
         Form1.updateLog_Callback d = new updateLog_Callback(updateLog);
         Form1.server.Invoke(d, new object[] { txt, level, whom });
     }
     else
     {
         System.Diagnostics.Trace.WriteLine(DateTime.Now.ToString("yyMMdd HH:mm:ss: [") +
             level.ToString() + "] " +
             txt);
         Form1.server.txtLog.AppendText(DateTime.Now.ToString("yyMMdd HH:mm:ss: [") +
             level.ToString()+"] " +
             txt + "\n");
     }
 }
Beispiel #11
0
 private string createLogEntry(ELogLevel eLogLevel, string sMessage, string sModule)
 {
     return eLogLevel.ToString () + " | " + sModule + " | " + sMessage;
 }
 public async Task Log(string message, ELogLevel level = ELogLevel.INFO)
 {
     if (level <= App.LogLevel)
     {
         string logMessage = LOG_FORMAT.Replace("%dt%", DateTime.Now.ToString()).Replace("%lv%", level.ToString()).Replace("%msg%", message);
         foreach (ILogger l in loggers)
         {
             try
             {
                 await l.Log(logMessage, level);
             }
             catch (Exception ex)
             {
                 try
                 {
                     Debug.WriteLine("Can't log in {0}. Exception: \n{1}\n{2}", l.GetType().FullName, ex.Message, ex.StackTrace);
                 }
                 finally { }
             }
         }
     }
 }
Beispiel #13
0
 public static void WriteLine(ELogLevel pLogLevel, string pFormat, params object[] pArgs)
 {
     OnOutput(DateTime.Now.ToString() + " <" + pLogLevel.ToString() + "> " + string.Format(pFormat, pArgs));
 }
Beispiel #14
0
 public string BuildLogEntry(string tag, ELogLevel logLevel, string message)
 => $"{logLevel.ToString().ToUpper()}:{tag}->{message}";
Beispiel #15
0
        /// <summary>
        /// Writes to the log.
        /// </summary>
        /// <param name="ELogLevel">Log Level</param>
        /// <param name="format">The format.</param>
        /// <param name="args">The arguments.</param>
        public static void Write(ELogLevel logLevel, string format, params object[] args)
        {
            string message = string.Format(format, args);

            if (logLevel == ELogLevel.Fatal)
            {
                OnEvent(message);
            }

            switch (LogType)
            {
            case ELogType.TxtFile:
                Writer writer = new Writer(Filepath);
                message = DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss") + " - Level: " + logLevel.ToString() + " - " + message;
                writer.WriteToFile(message);
                break;

            case ELogType.Console:
                System.Console.WriteLine(message);
                break;

            case ELogType.Debug:
                System.Diagnostics.Debug.WriteLine(message);
                break;

            default:
                System.Diagnostics.Debug.WriteLine(message);
                break;
            }
        }
Beispiel #16
0
 public static void WriteLine(ELogLevel pLogLevel, string pFormat, params object[] pArgs)
 {
     string buffer = DateTime.Now.ToString() + " (" + pLogLevel.ToString() + ") " + string.Format(pFormat, pArgs);
     lock (sLock) Console.WriteLine(buffer);
 }
Beispiel #17
0
 public static void WriteLog(ProjectSource projectSource, ELogLevel logLevel, String log)
 {
     CLoggerDataAccess.WriteLogToDB(projectSource.ToString(), logLevel.ToString(), log, null);
 }
Beispiel #18
0
 public static void WriteLog(ProjectSource projectSource, ELogLevel logLevel, String log, Exception exception)
 {
     WriteLogToDB(projectSource.ToString(), logLevel.ToString(), log, exception);
 }