Beispiel #1
0
        /// <summary>
        /// Comparer
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public static int ListSortCompare(FileLogData x, FileLogData y)
        {
            /*if (x == null)
             * {
             *  if (y == null)
             *      return 0;
             *  else
             *      return -1;
             * }
             * else
             * {
             *  if (y == null)
             *      return 1;
             *  else
             *  {*/
            if (x.time < y.time)
            {
                return(-1);
            }
            else if (x.time > y.time)
            {
                return(1);
            }
            else
            {
                return(0);
            }

            /*        }
             *  }*/
        }
Beispiel #2
0
        /// <summary>
        /// This static function logs after some time, till log all texts that send will be saved as lines.
        /// You can set interval to log.
        /// </summary>
        /// <param name="type">Type of the log</param>
        /// <param name="level">Log level of the log</param>
        /// <param name="text">Text</param>
        /// <param name="p">This parameter is only used on EventLog type, it gives an id to event</param>
        public static void LogTimed(LogType type, LogLevel level, string text, params int[] p)
        {
            if ((logLevel & level) == 0)
            {
                return;
            }

#if !NETFX_CORE
            switch (type)
            {
            case LogType.CONSOLE:
            {
                if (!timedConsoleLog.ContainsKey(level))
                {
                    timedConsoleLog.Add(level, new StringBuilder());
                }

                if (timedConsoleLog[level].ToString() == "")
                {
                    timerConsole.Start();
                    if (!timerConsoleAdded)
                    {
                        timerConsole.Tick += new EventHandler(ConsoleTimerLog);
                        timerConsoleAdded  = true;
                    }
                }

                timedConsoleLog[level].AppendLine(DateTime.Now.ToString() + ":" + level + ":" + Assembly.GetExecutingAssembly().GetName().Name + ":" + text);
            } break;

            case LogType.EVENTLOG:
            {
            } break;

            case LogType.FILE:
            {
                if (!timedFileLog.ContainsKey(level))
                {
                    timedFileLog.Add(level, new List <FileLogData>());
                }

                if (timedFileLog[level].Count == 0)
                {
                    timerFileLog.Start();
                    if (!timerFileLogAdded)
                    {
                        timerFileLog.Tick += new EventHandler(FileTimerLog);
                        timerFileLogAdded  = true;
                    }
                }

                FileLogData fld = new FileLogData();
                fld.level = level;
                fld.time  = DateTime.Now;
                fld.data  = Assembly.GetExecutingAssembly().GetName().Name + ":" + text;
                timedFileLog[level].Add(fld);
                //timedFileLog[level].AppendLine(DateTime.Now.ToString() + ":" + level + ":" + Assembly.GetEntryAssembly().GetName().Name + ":" + text);
            } break;
            }
            ;
#endif
        }