private static void WriteLog(string category, PriorityFlags logpriority, string message, Exception exception)
        {
            if (!IsContain(LogPriority, logpriority))
            {
                return;
            }

            StringBuilder log = new StringBuilder()
                                .Append(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff"))
                                .AppendFormat(" {0} [{1}]", logpriority,
                                              Thread.CurrentThread.Name.IfEmpty(() => Thread.CurrentThread.ManagedThreadId.ToString().PadRight(5)));

            if (!string.IsNullOrWhiteSpace(message))
            {
                log.Append(" Message:").Append(message);
            }

            if (exception != null)
            {
                log.Append(" Exception:").Append(exception);
                if (exception.InnerException != null)
                {
                    log.AppendLine().Append("InnerException:").Append(exception.InnerException);
                }
            }

            Trace.WriteLine(log.ToString(), category);
        }
Beispiel #2
0
        public bool ShouldLogMessage(PriorityFlags priorities, object objectToLog)
        {
            if (supressLogging > 0 || ExcludeAllTypes || (!WriteToDeviceConsole && !WriteToUnityConsole))
            {
                return(false);
            }
            bool flag = LogAllTypes && (priorities & LogAllTypesPriorities) > PriorityFlags.NONE;

            if (objectToLog != null)
            {
                Type key = (objectToLog as Type) ?? objectToLog.GetType();
                if (!typesToLogMap.TryGetValue(key, out var value) && LogAllTypes)
                {
                    value = LogAllTypesPriorities;
                }
                flag = flag || (priorities & value) > PriorityFlags.NONE;
                if (typesNotToLogMap.TryGetValue(key, out value))
                {
                    flag = flag && (priorities & value) <= PriorityFlags.NONE;
                }
            }
            else
            {
                flag = !ExcludeNullObjects && (priorities & NullPriorityFlags) > PriorityFlags.NONE;
            }
            return(flag);
        }
Beispiel #3
0
 private string GeneratePriorities(PriorityFlags priorities)
 {
     if (mShowPriorityNames)
     {
         return("[" + priorities.ToString() + "]");
     }
     return("");
 }
Beispiel #4
0
 private void generatePriorities(PriorityFlags priorities)
 {
     if (ShowPriorityNames)
     {
         messageBuilder.Append('[');
         messageBuilder.Append(priorities);
         messageBuilder.Append(']');
     }
 }
Beispiel #5
0
 private string assembleMessage(object objectToLog, PriorityFlags priorities, string message)
 {
     messageBuilder.Length = 0;
     generateTimeStamp();
     generatePriorities(priorities);
     generateObjectName(objectToLog);
     messageBuilder.Append(' ');
     messageBuilder.Append(message);
     serializeObject(objectToLog);
     return(messageBuilder.ToString());
 }
Beispiel #6
0
 private void LogMessage(object objectToLog, PriorityFlags priorities, TagFlags tags, string message)
 {
     if (mSuppressLogging == 0 && ShouldLogMessage(priorities, tags, objectToLog))
     {
         string value = FormatMessage(objectToLog, priorities, tags, message);
         mLoggerQueue.Enqueue(new KeyValuePair <PriorityFlags, string>(priorities, value));
         if (mFlushAfterEachLog)
         {
             FlushLog();
         }
     }
 }
Beispiel #7
0
        private string FormatMessage(object objectToLog, PriorityFlags priorities, TagFlags tags, string message)
        {
            string        text          = GenerateTimeStamp();
            string        text2         = GeneratePriorities(priorities);
            string        text3         = GenerateTagNames(tags);
            string        text4         = GenerateObjectName(objectToLog);
            string        text5         = SerializeObject(objectToLog);
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendFormat("{0}{1}{2}{3} {4} {5}", text, text3, text2, text4, message, text5);
            return(stringBuilder.ToString());
        }
Beispiel #8
0
        static TodoItem()
        {
            PriorityFlags.Add(PriorityFlag.High);
            PriorityFlags.Add(PriorityFlag.Normal);
            PriorityFlags.Add(PriorityFlag.Low);

            StatusFlags.Add(StatusFlag.NotStarted);
            StatusFlags.Add(StatusFlag.InProgress);
            StatusFlags.Add(StatusFlag.Deferred);
            StatusFlags.Add(StatusFlag.WaitingOnSomeoneElse);
            StatusFlags.Add(StatusFlag.Completed);
        }
        static NetFrameworkLogger()
        {
            LogAppender = ConfigurationManager.AppSettings["umizoo.log_appender"].IfEmpty("FILE").ToLower();
            LogPriority = GetLogPriority(ConfigurationManager.AppSettings["umizoo.log_priority"].IfEmpty("OFF"));

            if (LogAppender == "all" || LogAppender == "console")
            {
                Trace.Listeners.Add(new ConsoleTraceListener(false));
            }

            if (LogAppender == "all" || LogAppender == "file")
            {
                string logFile = CreateFile();
                Trace.Listeners.Add(new TextWriterTraceListener(logFile));
                Trace.AutoFlush = true;
            }
        }
Beispiel #10
0
 public override void Configure(IDictionary <string, object> dictionary)
 {
     base.Configure(dictionary);
     mPrioritiesToLog = (PriorityFlags)Enum.Parse(typeof(PriorityFlags), mPrioritiesToLogCSV, ignoreCase: true);
     mTagsToLog       = (TagFlags)Enum.Parse(typeof(TagFlags), mTagsToLogCSV, ignoreCase: true);
     if (mTypesToLog.Count > 0)
     {
         mLogAllTypes = false;
         for (int i = 0; i < mTypesToLog.Count; i++)
         {
             ParseTypesToLog(mTypesToLog[i] as string);
         }
     }
     else
     {
         ParseTypesToLog(mTypesToLogCSV);
     }
     CreateLogFilesDirectory(mLogFile);
 }
Beispiel #11
0
 private void ParseTypesToLog(string csvList)
 {
     if (string.IsNullOrEmpty(csvList) || csvList.Trim().Length == 0)
     {
         return;
     }
     string[] array  = csvList.Split(',');
     string[] array2 = array;
     foreach (string text in array2)
     {
         string[] array3 = text.Split(':');
         string   text2  = array3[0].Trim();
         Type     type   = Type.GetType(text2);
         if (string.Equals(text2, mAllTypes, StringComparison.OrdinalIgnoreCase))
         {
             mLogAllTypes = true;
             continue;
         }
         if (type == null)
         {
             Debug.LogError("Attempting to do per type logging on a type that does not exist. Verify the namespace and type name!");
             throw new InvalidCastException();
         }
         if (array3.Length > 1)
         {
             try
             {
                 PriorityFlags value = (PriorityFlags)Enum.Parse(typeof(PriorityFlags), array3[1]);
                 mTypesToLogMap[type] = value;
             }
             catch (Exception ex)
             {
                 Debug.LogWarning(string.Concat(ex, " parsing ", array3[1], " for type ", text2, " defaulting to ALL"));
                 mTypesToLogMap[type] = PriorityFlags.ALL;
             }
         }
         else
         {
             mTypesToLogMap[type] = PriorityFlags.ALL;
         }
     }
 }
Beispiel #12
0
        private void logMessage(object objectToLog, PriorityFlags priorities, string message, params object[] args)
        {
            if (!ShouldLogMessage(priorities, objectToLog))
            {
                return;
            }
            if (args.Length > 0)
            {
                message = string.Format(message, args);
            }
            string text = assembleMessage(objectToLog, priorities, message);

            UnityEngine.Object @object = objectToLog as UnityEngine.Object;
            if (WriteToUnityConsole)
            {
                if ((priorities & (PriorityFlags.ERROR | PriorityFlags.NETWORK_ERROR | PriorityFlags.FATAL)) != 0)
                {
                    UnityEngine.Debug.LogError(text, @object);
                }
                else if ((priorities & PriorityFlags.WARNING) == PriorityFlags.WARNING)
                {
                    UnityEngine.Debug.LogWarning(text, @object);
                }
                else
                {
                    UnityEngine.Debug.Log(text, @object);
                }
            }
            if (WriteToDeviceConsole)
            {
                consoleLog(text);
            }
            if (this.LogMessageEvent != null)
            {
                this.LogMessageEvent(@object, priorities, text);
            }
        }
Beispiel #13
0
 private static bool IsContain(PriorityFlags priority, PriorityFlags comparer)
 {
     return((priority & comparer) == comparer);
 }
Beispiel #14
0
 public void SetNotLogFlags(Type type, PriorityFlags flags)
 {
     typesNotToLogMap[type] = flags;
 }
Beispiel #15
0
        private bool ShouldLogMessage(PriorityFlags priorities, TagFlags tags, object objectToLog)
        {
            if (!mWriteToDeviceConsole && !mWriteToFile && !mWriteToUnityConsole)
            {
                return(false);
            }
            bool flag  = (priorities & mPrioritiesToLog) > PriorityFlags.NONE;
            bool flag2 = (tags & mTagsToLog) > (TagFlags)0;
            bool flag3 = mLogAllTypes;

            if (!flag3)
            {
                Type type = null;
                if (objectToLog is string)
                {
                    type = Type.GetType(objectToLog as string);
                }
                else if (objectToLog is Type)
                {
                    type = objectToLog as Type;
                }
                else if (objectToLog != null)
                {
                    type = objectToLog.GetType();
                }
                if (type != null)
                {
                    if (mTypesToLogMap.TryGetValue(type, out var value))
                    {
                        switch (value)
                        {
                        case PriorityFlags.NONE:
                            flag3 = false;
                            break;

                        case PriorityFlags.ALL:
                            flag3 = true;
                            break;

                        default:
                            flag3 = value <= priorities;
                            break;
                        }
                    }
                }
                else
                {
                    flag3 = false;
                }
            }
            bool result = false;

            if (mLogAllTypes)
            {
                result = ((flag2 && flag3 && flag) ? true : false);
            }
            else if (mTagsToLog != TagFlags.ALL)
            {
                result = ((!mTagAndTypeRestrictive) ? (flag3 || flag2) : (flag3 && flag2));
            }
            else if (flag3)
            {
                result = true;
            }
            else if (flag2)
            {
                result = (flag ? true : false);
            }
            else if (flag)
            {
                result = true;
            }
            return(result);
        }
Beispiel #16
0
 public static void Log(object objectToLog, PriorityFlags priorities, TagFlags tags, string message)
 {
     Instance.LogMessage(objectToLog, priorities, tags, message);
 }
Beispiel #17
0
 public static void LogRawFormatted(object objectToLog, PriorityFlags priorities, string message, params object[] args)
 {
     Instance.logMessage(objectToLog, priorities, message, args);
 }
Beispiel #18
0
 public static void LogRaw(object objectToLog, PriorityFlags priorities, string message)
 {
     Instance.logMessage(objectToLog, priorities, message);
 }