Пример #1
0
        private void LogToConsole(MsgLevel level, ErrReport report)
        {
            string msg = "";

            if (report.StackTrace.Length > 0)
            {
                //System.Diagnostics.Trace.WriteLine(String.Format("{0:00000}\t{1}\t{2}.{3} - {4}{5}{6}", report.Code, level.ShortName(), report.AtClass, report.AtMethod, report.Msg, Environment.NewLine, report.StackTrace));

                //msg = String.Format("{0:00000}\t{1}\t{2}.{3} - {4}{5}{6}", report.Code, level.ShortName(), report.AtClass, report.AtMethod, report.Msg, Environment.NewLine, report.StackTrace);
                msg = String.Format(
                    "{0}  {1:00000}\t{2}\t{3}.{4} - {5}{6}{7}",
                    report.TimeStamp.ToString("h:mm:ss fff"), report.Code,
                    level.ShortName(), report.AtClass, report.AtMethod,
                    report.Msg, Environment.NewLine, report.StackTrace);
            }
            else
            {
                //System.Diagnostics.Trace.WriteLine(String.Format("{0:00000}\t{1}\t{2}.{3} - {4}", report.Code, level.ShortName(), report.AtClass, report.AtMethod, report.Msg));
                //msg = String.Format("{0:00000}\t{1}\t{2}.{3} - {4}", report.Code, level.ShortName(), report.AtClass, report.AtMethod, report.Msg);
                msg = String.Format(
                    "{0} {1:00000}\t{2}\t{3}.{4} - {5}",
                    report.TimeStamp.ToString("h:mm:ss fff"), report.Code,
                    level.ShortName(), report.AtClass, report.AtMethod, report.Msg);
            }

            System.Diagnostics.Trace.WriteLine(msg);
        }
Пример #2
0
 public MsgBox(MsgLevel msgLevel, string message)
 {
     InitializeComponent();
     ShowCancelBtn(msgLevel);
     info_tbox.Text = message;
     AssignPicture(msgLevel);
 }
Пример #3
0
        private static string ToDisplayString(this MsgLevel level)
        {
            switch (level)
            {
            case MsgLevel.Error:
                return("ERROR: ");

            case MsgLevel.Warning:
                return("Warning: ");

            case MsgLevel.Normal:
                return("Info: ");

            case MsgLevel.Debug:
                return("Debug L1: ");

            case MsgLevel.DDebug:
                return("Debug L2: ");

            case MsgLevel.DDDebug:
                return("Debug L3: ");

            case MsgLevel.DDDDebug:
                return("Debug L4: ");

            default:
                return(string.Empty);
            }
        }
Пример #4
0
        /// <summary>
        /// Writes message to the given output. Terminated by NewLine
        /// </summary>
        /// <param name="level">The level of the message.</param>
        /// <param name="format">The message/format string for string.Format().</param>
        /// <param name="args">List of parameters to be inserted in <paramref name="format"/> by string.Format()</param>
        public static void WriteLine(string format = "", MsgLevel level = MsgLevel.Normal, params object[] args)
        {
            if (MessageLevel == MsgLevel.Silent || level > MessageLevel)
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(format))
            {
                Write(NewLine);
                return;
            }

            string message = string.Empty;

            if (DisplayTime)
            {
                message += DateTime.Now.ToShortTimeString();
            }
            if (DisplayMessageLevel)
            {
                message += level.ToDisplayString();
            }
            message += string.Format(format, args);
            message += NewLine;
            Write(message);
        }
Пример #5
0
        /// <summary>
        /// Writes <paramref name="format"/> to the OutputStream with <paramref name="indent"/> characters
        /// of IndentationChars before and broke to new line after MaxLineLength characters.
        /// Format is processed by string.Format() with <paramref name="args"/> passed to it.
        /// The message is always terminated by a newline.
        /// </summary>
        /// <param name="level">The level of the message.</param>
        /// <param name="format">The message/format string for string.Format().</param>
        /// <param name="indent">Number of indentation to be inserted before every line.</param>
        /// <param name="args">List of parameters to be inserted in <paramref name="format"/> by string.Format()</param>
        public static void WriteWithBreak(string format = "", MsgLevel level = MsgLevel.Normal, int indent = 0, params object[] args)
        {
            if (MessageLevel == MsgLevel.Silent || level > MessageLevel)
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(format))
            {
                Write(NewLine);
                return;
            }

            string message = string.Format(format, args);

            if (message.Length + indent <= MaxLineLength && !message.Contains("\n"))
            {
                if (indent > 0)
                {
                    Write(new string(IndentationChar, indent) + message + NewLine);
                }
                else
                {
                    Write(message + NewLine);
                }
                return;
            }

            string indentStr = new string(IndentationChar, indent);

            foreach (var line in message.Replace("\r", "").Split('\n'))
            {
                int currentLength = 0;
                if (indent > 0)
                {
                    Write(indentStr);
                    currentLength += indent;
                }
                foreach (var word in line.Split(' '))
                {
                    if (currentLength + word.Length + 1 <= MaxLineLength)
                    {
                        Write(word + " ");
                        currentLength += word.Length + 1;
                    }
                    else
                    {
                        currentLength = 0;
                        Write(NewLine);
                        if (indent > 0)
                        {
                            Write(indentStr);
                            currentLength += indent;
                        }
                        Write(word + " ");
                        currentLength += word.Length + 1;
                    }
                }
                Write(NewLine);
            }
        }
Пример #6
0
        public void AssignPicture(MsgLevel level)
        {
            string imagePath = "";

            try
            {
                switch (level)
                {
                case MsgLevel.Info:
                    imagePath = infoImage;
                    break;     // TODO: might not be correct. Was : Exit Select

                case MsgLevel.Mistake:
                    imagePath = errorImage;
                    break;     // TODO: might not be correct. Was : Exit Select

                case MsgLevel.Successful:
                    imagePath = successImage;
                    break;     // TODO: might not be correct. Was : Exit Select

                case MsgLevel.Warning:
                    imagePath = warningImage;
                    break;     // TODO: might not be correct. Was : Exit Select
                }
                this.Indicator.Source = new BitmapImage(new Uri(imagePath, UriKind.Absolute));
            }
            catch (Exception ex)
            {
            }
        }
        /// <summary>
        /// Log写入
        /// </summary>
        /// <param name="logBean"></param>
        public void WriteLog(MsgLevel level, string message)
        {
            switch (level)
            {
            case MsgLevel.Debug:
                basicLog?.Debug(message);
                break;

            case MsgLevel.Info:
                basicLog?.Info(message);
                break;

            case MsgLevel.Warn:
                basicLog?.Warn(message);
                break;

            case MsgLevel.Error:
                errLog?.Error(message);
                break;

            case MsgLevel.Fatal:
                errLog?.Fatal(message);
                break;
            }
        }
Пример #8
0
        /// <summary>
        /// 创建系统日志
        /// </summary>
        /// <param name="level">级别</param>
        /// <param name="type">类名,可自定义</param>
        /// <param name="parasHashtable">自定义参数,目前固定三个{UserId;IP;FunName}</param>
        /// <param name="message">内容</param>
        public void Log(MsgLevel level, System.String type, Hashtable parasHashtable, object message)
        {
            switch (level)
            {
            case MsgLevel.Debug:
                MyLog.Debug(type, parasHashtable, message);
                break;

            case MsgLevel.Info:
                MyLog.Info(type, parasHashtable, message);
                break;

            case MsgLevel.Warn:
                MyLog.Warn(type, parasHashtable, message);
                break;

            case MsgLevel.Error:
                MyLog.Error(type, parasHashtable, message);
                break;

            case MsgLevel.Fatal:
                MyLog.Fatal(type, parasHashtable, message);
                break;
            }
        }
Пример #9
0
        internal void SendMessage(MsgLevel lvl, string text)
        {
            if (lvl >= (MsgLevel)Config.GetInt("MessageLevel") && text.Length > 0)
            {
                int hue;
                switch (lvl)
                {
                case MsgLevel.Error:
                case MsgLevel.Warning:
                    hue = Config.GetInt("WarningColor");
                    break;

                default:
                    hue = Config.GetInt("SysColor");
                    break;
                }

                ClientCommunication.SendToClient(new UnicodeMessage(0xFFFFFFFF, -1, MessageType.Regular, hue, 3, Language.CliLocName, "System", text));

                PacketHandlers.SysMessages.Add(text.ToLower());

                if (PacketHandlers.SysMessages.Count >= 25)
                {
                    PacketHandlers.SysMessages.RemoveRange(0, 10);
                }
            }
        }
Пример #10
0
        internal void SendMessage(MsgLevel lvl, string text)
        {
            if (lvl < (MsgLevel)RazorEnhanced.Settings.General.ReadInt("MessageLevel") || text.Length <= 0)
            {
                return;
            }

            int hue;

            switch (lvl)
            {
            case MsgLevel.Error:
            case MsgLevel.Warning:
                hue = Engine.MainWindow.WarningColor;
                break;

            default:
                hue = Engine.MainWindow.SysColor;
                break;
            }
            Assistant.Client.Instance.SendToClient(new UnicodeMessage(0xFFFFFFFF, -1, MessageType.Regular, hue, 3, Language.CliLocName, "System", text));

            PacketHandlers.SysMessages.Add(text.ToLower());

            if (PacketHandlers.SysMessages.Count >= 25)
            {
                PacketHandlers.SysMessages.RemoveRange(0, 10);
            }
        }
Пример #11
0
        /// <summary>
        /// 创建系统日志
        /// </summary>
        /// <param name="level">级别</param>
        /// <param name="type">类名,可自定义</param>
        /// <param name="parasHashtable">自定义参数,目前固定三个{UserId;IP;FunName}</param>
        /// <param name="message">内容</param>
        public void Log(MsgLevel level, System.String type, Hashtable parasHashtable, object message)
        {
            switch (level)
            {
            case MsgLevel.DEBUG:
                MyLog.Debug(type, parasHashtable, message);
                break;

            case MsgLevel.INFO:
                MyLog.Info(type, parasHashtable, message);
                break;

            case MsgLevel.WARN:
                MyLog.Warn(type, parasHashtable, message);
                break;

            case MsgLevel.ERROR:
                MyLog.Error(type, parasHashtable, message);
                break;

            case MsgLevel.FATAL:
                MyLog.Fatal(type, parasHashtable, message);
                break;
            }
        }
Пример #12
0
 private void LogToConsole(MsgLevel level, ErrReport report)
 {
     if (report.StackTrace.Length > 0) {
         Console.WriteLine("{0}\t{1}\t{2}.{3} - {4}{5}{6}", report.Code, level.ShortName(), report.AtClass, report.AtMethod, report.Msg, Environment.NewLine, report.StackTrace);
     }
     else {
         Console.WriteLine("{0}\t{1}\t{2}.{3} - {4}", report.Code, level.ShortName(), report.AtClass, report.AtMethod, report.Msg);
     }
 }
Пример #13
0
        public void Setup()
        {
            LogUtils.Log.SetVerbosity(MsgLevel.Info);
            LogUtils.Log.SetMsgNumberThreshold(1);
            this.consoleWriter.StartLogging();

            this.currentLevel  = MsgLevel.Off;
            this.currentReport = new ErrReport();
        }
Пример #14
0
 public static int ToInt(this MsgLevel level)
 {
     try {
         return(Convert.ToInt32(level));
     }
     catch (Exception) {
         return((int)MsgLevel.Info);
     }
 }
Пример #15
0
 /// <summary>
 /// Checks if the message level is equal or greater than the set verbosity
 /// </summary>
 /// <param name="msgLevel">The message level</param>
 /// <returns></returns>
 private static bool IsVerboseEnough(MsgLevel msgLevel)
 {
     // Initial check for illegal usage of Off for a message level
     if (msgLevel == MsgLevel.Off)
     {
         return(false);
     }
     return(msgLevel.GreaterOrEqual(Log.verbosity));
 }
Пример #16
0
 /// <summary>
 /// Retrieves the class and method names by reflection. Used for messages from warning to
 /// Exception level with occur infrequently
 /// </summary>
 /// <param name="level">Log message level</param>
 /// <param name="code">Error code</param>
 /// <param name="msg">Error message</param>
 /// <param name="e">The exception to parse for information</param>
 private static void LogWarningAndUp(MsgLevel level, int code, string msg, Exception e)
 {
     // Do the verbosity check first to avoid the overhead of reflection if it is not being logged
     if (Log.IsVerboseEnough(level))
     {
         MethodBase mb = StackFrameTools.FirstNonWrappedMethod(typeof(LogUtils.Log));
         Log.LogMsg(level, code, mb.DeclaringType.Name, mb.Name, msg, e);
     }
 }
Пример #17
0
        public MsgArgs(string msg, MsgLevel level = MsgLevel.Debug)
        {
            content    = msg;
            this.level = level;
            stamp      = DateTime.Now;

#if LSR_FEATURE_S_VECTOR
            vector = Track();
#endif
        }
Пример #18
0
        public InfoBoard(MsgLevel level, string[] msg, int autoCloseInterval)
        {
            InitializeComponent();
            this.AssignPicture(level);
            this.AssignText(ArrayToString(msg));

            timer = new System.Timers.Timer();
            timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_elsped);
            timer.Interval = autoCloseInterval;
            timer.Start();
        }
Пример #19
0
 private void LogToConsole(MsgLevel level, ErrReport report)
 {
     if (report.StackTrace.Length > 0)
     {
         Console.WriteLine("{0}\t{1}\t{2}.{3} - {4}{5}{6}", report.Code, level.ShortName(), report.AtClass, report.AtMethod, report.Msg, Environment.NewLine, report.StackTrace);
     }
     else
     {
         Console.WriteLine("{0}\t{1}\t{2}.{3} - {4}", report.Code, level.ShortName(), report.AtClass, report.AtMethod, report.Msg);
     }
 }
Пример #20
0
        public void LogToConsole(MsgLevel level, ErrReport report)
        {
            this.writer.WriteToConsole(level, report);

            //if (report.StackTrace.Length > 0) {
            //    writer.WriteToConsole(string.Format("{0} {1}\t{2}\t{3}.{4} - {5}{6}{7}", report.TimeStamp.ToString("h:mm:ss fff"), report.Code, level.ShortName(), report.AtClass, report.AtMethod, report.Msg, Environment.NewLine, report.StackTrace));
            //}
            //else {
            //    writer.WriteToConsole(string.Format("{0} {1}\t{2}\t{3}.{4} - {5}", report.TimeStamp.ToString("h:mm:ss fff"), report.Code, level.ShortName(), report.AtClass, report.AtMethod, report.Msg));
            //}
        }
Пример #21
0
 public void WriteToConsole(MsgLevel level, ErrReport report)
 {
     if (report.StackTrace.Length > 0)
     {
         Console.WriteLine("{0} {1}\t{2}\t{3}.{4} - {5}{6}{7}", report.TimeStamp.ToString("h:mm:ss fff"), report.Code, level.ShortName(), report.AtClass, report.AtMethod, report.Msg, Environment.NewLine, report.StackTrace);
     }
     else
     {
         Console.WriteLine("{0} {1}\t{2}\t{3}.{4} - {5}", report.TimeStamp.ToString("h:mm:ss fff"), report.Code, level.ShortName(), report.AtClass, report.AtMethod, report.Msg);
     }
 }
Пример #22
0
 /// <summary>
 /// Push the log message to the log message event subscribers
 /// </summary>
 /// <param name="eventData"></param>
 private static void RaiseEvent(MsgLevel level, ErrReport msg)
 {
     if (Log.OnLogMsgEvent != null)
     {
         WrapErr.SafeAction(() => Log.OnLogMsgEvent(level, msg));
     }
     else
     {
         System.Diagnostics.Debug.WriteLine("No subscribers to log message event");
     }
 }
Пример #23
0
        public InfoBoard(MsgLevel level, string[] msg, int autoCloseInterval)
        {
            InitializeComponent();
            this.AssignPicture(level);
            this.AssignText(ArrayToString(msg));

            timer          = new System.Timers.Timer();
            timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_elsped);
            timer.Interval = autoCloseInterval;
            timer.Start();
        }
Пример #24
0
 /// <summary>
 /// Log the message
 /// </summary>
 /// <param name="level">The message level</param>
 /// <param name="msg">The message object</param>
 public static void LogMsg(MsgLevel level, ErrReport msg)
 {
     if (Log.IsVerboseEnough(level))
     {
         lock (Log.msgQLock) {
             Log.messages.Add(new KeyValuePair <MsgLevel, ErrReport>(level, msg));
             if (Log.messages.Count >= Log.msgNumberThreshold)
             {
                 Log.msgWaitEvent.Set();
             }
         }
     }
 }
Пример #25
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="level">Log level verbosity</param>
        /// <param name="numberOfMsgBeforeDumpToLog">How many messages are put out before they are dumped to log</param>
        public HelperLogReader(MsgLevel level, int numberOfMsgBeforeDumpToLog)
        {
            // Create delegate to attach to Log
            this.myLogReadDelegate = new LogingMsgEventDelegate(this.Log_OnLogMsgEvent);

            // Set log verbosity and number of messages that have to arrive before the log
            // thread fires
            Log.SetVerbosity(level);
            Log.SetMsgNumberThreshold(numberOfMsgBeforeDumpToLog);

            // Stream the errors caught by WrapErr to the Log
            WrapErr.InitialiseOnExceptionLogDelegate(Log.LogExceptionDelegate);
        }
Пример #26
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="level">Log level verbosity</param>
        /// <param name="numberOfMsgBeforeDumpToLog">How many messages are put out before they are dumped to log</param>
        public HelperLogReader(MsgLevel level, int numberOfMsgBeforeDumpToLog)
        {
            // Create delegate to attach to Log
            this.myLogReadDelegate = new LogingMsgEventDelegate(this.Log_OnLogMsgEvent);

            // Set log verbosity and number of messages that have to arrive before the log
            // thread fires
            Log.SetVerbosity(level);
            Log.SetMsgNumberThreshold(numberOfMsgBeforeDumpToLog);

            // Stream the errors caught by WrapErr to the Log
            WrapErr.InitialiseOnExceptionLogDelegate(Log.LogExceptionDelegate);
        }
Пример #27
0
 public static void WriteLog(string info, MsgLevel msgLevel, Exception ex, bool ShowMsgBox = false)
 {
     if (logerror.IsErrorEnabled)
     {
         logerror.Error(info, ex);
     }
     logQueue.Enqueue(new LogInfo {
         message = info, ex = ex, logLevel = msgLevel
     });
     if (ShowMsgBox)
     {
         MessageBox.Show(info);
     }
 }
Пример #28
0
 public static void WriteLog(string info, MsgLevel msgLevel, bool ShowMsgBox = false)
 {
     if (loginfo.IsInfoEnabled)
     {
         loginfo.Info(info);
     }
     logQueue.Enqueue(new LogInfo {
         message = info, ex = null, logLevel = msgLevel
     });
     if (ShowMsgBox)
     {
         MessageBox.Show(info);
     }
 }
Пример #29
0
        /// <summary>
        /// Safely pass a Log message to the logger implementation
        /// </summary>
        /// <param name="level">The loging level of the message</param>
        /// <param name="err">The error report object with the information</param>
        void Log_OnLogMsgEvent(MsgLevel level, ErrReport err)
        {
            if (this.loggerImpl != null)
            {
                try {
                    string msg = "NO MSG";
                    if (err.StackTrace.Length > 0)
                    {
                        msg = String.Format(
                            "{0}\t{1}\t{2}\t{3}.{4} {5}{6}{7}",
                            err.TimeStamp.ToString("h:mm:ss fff"), this.LogLevelShort(level), err.Code, err.AtClass, err.AtMethod, err.Msg, Environment.NewLine, err.StackTrace);
                    }
                    else
                    {
                        msg = String.Format(
                            "{0}\t{1}\t{2}\t{3}.{4} {5}",
                            err.TimeStamp.ToString("h:mm:ss fff"), this.LogLevelShort(level), err.Code, err.AtClass, err.AtMethod, err.Msg);
                    }

                    switch (level)
                    {
                    case MsgLevel.Info:
                        loggerImpl.Info(msg);
                        break;

                    case MsgLevel.Debug:
                        loggerImpl.Debug(msg);
                        break;

                    case MsgLevel.Warning:
                        loggerImpl.Warn(msg);
                        break;

                    case MsgLevel.Error:
                    case MsgLevel.Exception:
                        loggerImpl.Error(msg);
                        break;
                    }

#if SEND_LOG_TO_DEBUG
                    Debug.WriteLine(msg);
#endif
                }
                catch (Exception e) {
                    WrapErr.SafeAction(() => Debug.WriteLine(String.Format("Exception on logging out message:{0}", e.Message)));
                }
            }
        }
Пример #30
0
        internal void SendMessage(MsgLevel lvl, string text)
        {
            if (lvl >= (MsgLevel)Config.GetInt("MessageLevel") && text.Length > 0)
            {
                int hue;
                switch (lvl)
                {
                case MsgLevel.Error:
                case MsgLevel.Warning:
                    hue = Config.GetInt("WarningColor");
                    break;

                case MsgLevel.Friend:
                    hue = 63;
                    break;

                default:
                    hue = Config.GetInt("SysColor");
                    break;
                }

                PacketHandlers.SysMessages.Add(text);

                if (PacketHandlers.SysMessages.Count >= 25)
                {
                    PacketHandlers.SysMessages.RemoveRange(0, 10);
                }

                PacketHandlers.JournalMessages.Add(text);

                if (PacketHandlers.JournalMessages.Count >= 25)
                {
                    PacketHandlers.JournalMessages.RemoveRange(0, 10);
                }

                if (Config.GetBool("FilterRazorMessages"))
                {
                    if (!MessageQueue.Enqueue(0xFFFFFFFF, null, 0, MessageType.Regular, (ushort)hue, 3,
                                              Language.CliLocName, "System", text))
                    {
                        return;
                    }
                }

                Client.Instance.SendToClient(new UnicodeMessage(0xFFFFFFFF, -1, MessageType.Regular, hue, 3,
                                                                Language.CliLocName, "System", text));
            }
        }
Пример #31
0
        private static void OnToggleEnableDisable()
        {
            m_Enabled = !m_Enabled;

            MsgLevel type = MsgLevel.Warning;

            if (m_Enabled)
            {
                type = MsgLevel.Info;
            }

            if (World.Player != null)
            {
                World.Player.SendMessage(type, UpdateStatus());
            }
        }
Пример #32
0
        public void CheckLogValues(MsgLevel level, int code, string atClass, string atMethod, string msg, string stack)
        {
            Thread.Sleep(250);
            Assert.AreEqual(level, this.currentLevel, "Level Mismatch");
            Assert.AreEqual(code, this.currentReport.Code, "Error Code Mismatch");
            Assert.AreEqual(atClass, this.currentReport.AtClass, "Class Name Mismatch");
            Assert.AreEqual(atMethod, this.currentReport.AtMethod, "Method Name Mismatch");
            Assert.AreEqual(msg, this.currentReport.Msg, "Message Mismatch");

            if (stack.Length == 0) {
                Assert.AreEqual("", this.currentReport.StackTrace, "Stack trace supposed to be empty");
            }
            else {
                Assert.IsTrue(this.currentReport.StackTrace.Contains(stack), String.Format("Stack does not contain '{0}' - {1}", stack, this.currentReport.StackTrace));
            }
        }
Пример #33
0
        /// <summary>
        /// Make a log to console
        /// </summary>
        /// <param name="str">Contents to be logged</param>
        /// <param name="level">Message level which decides the printing color</param>
        public static void WriteLine(string str, MsgLevel level = MsgLevel.Default)
        {
            if (Released)
            {
                return;
            }

            string msg = "";

            if (bGuiConsole)
            {
                LogGuiConsoleResult = delegateLogGuiConsole.BeginInvoke(
                    msg: str,
                    bInnerLog: false,
                    bAllowTracing: true,
                    callback: LogGuiConsoleCallback,
                    @object: str);
                return;
            }

            msg = Prefix.Trim() + "[" + DateTime.Now.ToString("HH:mm:ss") + "] " + str;
            //Color switch
            switch (level)
            {
            case MsgLevel.Harmless:
                System.Console.ForegroundColor = HarmlessColor;
                break;

            case MsgLevel.Redirected:
                System.Console.ForegroundColor = RedirectedColor;
                break;

            case MsgLevel.Further:
                System.Console.ForegroundColor = FurtherColor;
                break;

            case MsgLevel.Critical:
                System.Console.ForegroundColor = CriticalColor;
                break;

            default:
                System.Console.ForegroundColor = DefaultColor;
                break;
            }

            System.Console.WriteLine(msg);
        }
Пример #34
0
        /// <summary>
        /// Translate log level to single char
        /// </summary>
        /// <param name="level">The log level</param>
        /// <returns>One char level or 'U' is not found</returns>
        private string LogLevelShort(MsgLevel level)
        {
            switch (level)
            {
            case MsgLevel.Info: return("I");

            case MsgLevel.Debug: return("D");

            case MsgLevel.Warning: return("W");

            case MsgLevel.Error: return("E");

            case MsgLevel.Exception: return("X");

            default: return("U");
            }
        }
Пример #35
0
        private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index < 0)
            {
                return;
            }
            else
            {
                e.DrawBackground();
                Brush mybsh = Brushes.Black;
                // 判断是什么类型的标签,在调用时必须信息前边标注信息的类别,分为Info,Warning,Error
                try
                {
                    MsgLevel msgLevel = (MsgLevel)Enum.Parse(typeof(MsgLevel), listBox1.Items[e.Index].ToString().Split('>')[1].Trim().Split(',')[0]);
                    switch (msgLevel)
                    {
                    case MsgLevel.Info:
                        mybsh = Brushes.Green;
                        break;

                    case MsgLevel.Debug:
                        mybsh = Brushes.Green;
                        break;

                    case MsgLevel.Warn:
                        mybsh = Brushes.Purple;
                        break;

                    case MsgLevel.Exception:
                    case MsgLevel.Fatal:
                        mybsh = Brushes.Red;
                        break;

                    default:
                        mybsh = Brushes.Black;
                        break;
                    }
                }
                catch (Exception)
                {
                    mybsh = Brushes.Green;
                }
                e.DrawFocusRectangle();
                e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font, mybsh, e.Bounds, StringFormat.GenericDefault);
            }
        }
Пример #36
0
 public void AssignPicture(MsgLevel level)
 {
     string imagePath = "";
     switch (level)
     {
         case MsgLevel.Info:
             imagePath = infoImage;
             break;
         case MsgLevel.Mistake:
             imagePath = errorImage;
             break;
         case MsgLevel.Successful:
             imagePath = successImage;
             break;
         case MsgLevel.Warning:
             imagePath = warningImage;
             break;
         case MsgLevel.Question:
             imagePath = questionImage;
             break;
     }
     this.info_img.Source = new BitmapImage(new Uri(imagePath, UriKind.Absolute));
 }
Пример #37
0
 /// <summary>
 /// Retrieves the class and method names by reflection. Used for messages from warning to 
 /// Exception level with occur infrequently
 /// </summary>
 /// <param name="level">Log message level</param>
 /// <param name="code">Error code</param>
 /// <param name="msg">Error message</param>
 private static void LogWarningAndUp(MsgLevel level, int code, string msg)
 {
     LogWarningAndUp(level, code, msg, null);
 }
Пример #38
0
 void Log_OnLogMsgEvent(MsgLevel level, ErrReport errReport)
 {
     this.currentLevel = level;
     this.currentReport = errReport;
 }
Пример #39
0
 internal void SendMessage( MsgLevel lvl, LocString loc )
 {
     SendMessage( lvl, Language.GetString( loc ) );
 }
Пример #40
0
 internal void SendMessage( MsgLevel lvl, LocString loc, params object[] args )
 {
     SendMessage( lvl, Language.Format( loc, args ) );
 }
Пример #41
0
 /// <summary>
 /// Set the minimum verbosity that the message need for logging
 /// </summary>
 /// <param name="minimumLevelForLogging">The minimum level required</param>
 public static void SetVerbosity(MsgLevel minimumLevelForLogging)
 {
     lock (Log.levelLock) {
         Log.verbosity = minimumLevelForLogging;
     }
 }
Пример #42
0
 /// <summary>
 /// Push the log message to the log message event subscribers
 /// </summary>
 /// <param name="eventData"></param>
 private static void RaiseEvent(MsgLevel level, ErrReport msg)
 {
     if (Log.OnLogMsgEvent != null) {
         WrapErr.SafeAction(() => Log.OnLogMsgEvent(level, msg));
     }
     else {
         System.Diagnostics.Debug.WriteLine("No subscribers to log message event");
     }
 }
Пример #43
0
 /// <summary>
 /// Log the message
 /// </summary>
 /// <param name="level">Message level</param>
 /// <param name="code">Error code</param>
 /// <param name="atClass">Class of origine</param>
 /// <param name="atMethod">Method of origine</param>
 /// <param name="msg">Message</param>
 /// <param name="e">Exception to log</param>
 public static void LogMsg(MsgLevel level, int code, string atClass, string atMethod, string msg, Exception e)
 {
     Log.LogMsg(level, new ErrReport(code, atClass, atMethod, msg, e));
 }
Пример #44
0
 /*internal void SendMessage( int hue, LocString loc, params object[] args )
 {
     SendMessage( hue, Language.Format( loc, args ) );
 }*/
 internal void SendMessage( MsgLevel lvl, string format, params object[] args )
 {
     SendMessage( lvl, String.Format( format, args ) );
 }
Пример #45
0
        public void Setup()
        {
            LogUtils.Log.SetVerbosity(MsgLevel.Info);
            LogUtils.Log.SetMsgNumberThreshold(1);
            this.consoleWriter.StartLogging();

            this.currentLevel = MsgLevel.Off;
            this.currentReport = new ErrReport();
        }
Пример #46
0
 /// <summary>
 /// Retrieves the class and method names by reflection. Used for messages from warning to 
 /// Exception level with occur infrequently
 /// </summary>
 /// <param name="level">Log message level</param>
 /// <param name="code">Error code</param>
 /// <param name="msg">Error message</param>
 /// <param name="e">The exception to parse for information</param>
 private static void LogWarningAndUp(MsgLevel level, int code, string msg, Exception e)
 {
     // Do the verbosity check first to avoid the overhead of reflection if it is not being logged
     if (Log.IsVerboseEnough(level)) {
         MethodBase mb = StackFrameTools.FirstNonWrappedMethod(typeof(LogUtils.Log));
         Log.LogMsg(level, code, mb.DeclaringType.Name, mb.Name, msg, e);
     }
 }
Пример #47
0
 public void CheckLogValues(MsgLevel level, int code, string atMethod, string msg, string stack)
 {
     this.CheckLogValues(level, code, "LogTests", atMethod, msg, stack);
 }
Пример #48
0
 /// <summary>
 /// Log the message using a function that defers execution of message formating unless at the 
 /// correct level to log
 /// </summary>
 /// <param name="level">Message level</param>
 /// <param name="code">Error code</param>
 /// <param name="atClass">Class of origine</param>
 /// <param name="atMethod">Method of origine</param>
 /// <param name="msg">Message function</param>
 public static void LogMsg(MsgLevel level, int code, string atClass, string atMethod, Func<string> msgFunc)
 {
     Log.LogMsg(level, code, atClass, atMethod, msgFunc, null);
 }
Пример #49
0
        internal void SendMessage( MsgLevel lvl, string text )
        {
            if ( lvl >= (MsgLevel)Config.GetInt( "MessageLevel" ) && text.Length > 0 )
            {
                int hue;
                switch ( lvl )
                {
                    case MsgLevel.Error:
                    case MsgLevel.Warning:
                        hue = Config.GetInt( "WarningColor" );
                        break;

                    default:
                        hue = Config.GetInt( "SysColor" );
                        break;
                }

                ClientCommunication.SendToClient( new UnicodeMessage( 0xFFFFFFFF, -1, MessageType.Regular, hue, 3, Language.CliLocName, "System", text ) );

                PacketHandlers.SysMessages.Add( text.ToLower() );

                if ( PacketHandlers.SysMessages.Count >= 25 )
                    PacketHandlers.SysMessages.RemoveRange( 0, 10 );
            }
        }
Пример #50
0
 /// <summary>
 /// Retrieves the class and method names by reflection. Used for messages from warning to 
 /// Exception level with occur infrequently. The message is delivered by delegate for 
 /// better performance when using formated error string.
 /// </summary>
 /// <param name="level">Log message level</param>
 /// <param name="code">Error code</param>
 /// <param name="msg">Error message</param>
 private static void LogWarningAndUp(MsgLevel level, int code, Func<string> msgFunc)
 {
     LogWarningAndUp(level, code, msgFunc, null);
 }
Пример #51
0
 /// <summary>
 /// Log the message using a function that defers execution of message formating unless at the 
 /// correct level to log
 /// </summary>
 /// <param name="level">Message level</param>
 /// <param name="code">Error code</param>
 /// <param name="atClass">Class of origine</param>
 /// <param name="atMethod">Method of origine</param>
 /// <param name="msg">Message function</param>
 /// <param name="e">Exception to log</param>
 public static void LogMsg(MsgLevel level, int code, string atClass, string atMethod, Func<string> msgFunc, Exception e)
 {
     // You must only invoke the formater function if the level is high enough to ensure maximum
     // performance gains if the message is not high enough level to be logged
     if (Log.IsVerboseEnough(level)) {
         string msg = "";
         try {
             msg = msgFunc.Invoke();
         }
         catch (Exception ex) {
             msg = String.Format(
                 "Exception Thrown on invoking Msg Formater for Msg Number:{0} at {1}.{2} - {3}",
                 code, atClass, atMethod, ex.Message);
             System.Diagnostics.Debug.WriteLine(msg);
         }
         Log.LogMsg(level, code, atClass, atMethod, msg, e);
     }
 }
Пример #52
0
 /// <summary>
 /// 写入新日志,根据指定的日志内容和信息类型,采用当前时间为日志时间写入新日志
 /// </summary>
 /// <param name="text">日志内容</param>
 /// <param name="type">信息类型</param>
 public void LogWrite(string text, MsgLevel type)
 {
     LogWrite(new Msg(text, type));
 }
Пример #53
0
 /// <summary>
 /// Log the message
 /// </summary>
 /// <param name="level">Message level</param>
 /// <param name="code">Error code</param>
 /// <param name="atClass">Class of origine</param>
 /// <param name="atMethod">Method of origine</param>
 /// <param name="msg">Message</param>
 public static void LogMsg(MsgLevel level, int code, string atClass, string atMethod, string msg)
 {
     Log.LogMsg(level, code, atClass, atMethod, msg, null);
 }
Пример #54
0
 /// <summary>
 /// 写入新日志,根据指定的日志时间、日志内容和信息类型写入新日志
 /// </summary>
 /// <param name="dt">日志时间</param>
 /// <param name="text">日志内容</param>
 /// <param name="type">信息类型</param>
 public void LogWrite(DateTime dt, string text, MsgLevel type)
 {
     LogWrite(new Msg(dt, text, type));
 }
Пример #55
0
 /// <summary>
 /// Set level message needs before being logged
 /// </summary>
 /// <param name="level">Required level</param>
 public void SetVerbosity(MsgLevel level)
 {
     Log.SetVerbosity(level);
 }
Пример #56
0
 /// <summary>
 /// 创建新的日志记录实例;日志事件为当前时间
 /// </summary>
 /// <param name="t">日志记录的文本内容</param>
 /// <param name="p">日志记录的消息类型</param>
 public Msg(string t, MsgLevel p)
     : this(DateTime.Now, t, p)
 {
 }
Пример #57
0
 /// <summary>
 /// 创建新的日志记录实例;
 /// </summary>
 /// <param name="dt">日志记录的时间</param>
 /// <param name="t">日志记录的文本内容</param>
 /// <param name="p">日志记录的消息类型</param>
 public Msg(DateTime dt, string t, MsgLevel p)
 {
     datetime = dt;
     type = p;
     text = t;
 }
Пример #58
0
 /// <summary>
 /// Log the message
 /// </summary>
 /// <param name="level">The message level</param>
 /// <param name="msg">The message object</param>
 public static void LogMsg(MsgLevel level, ErrReport msg)
 {
     if (Log.IsVerboseEnough(level)) {
         lock (Log.msgQLock) {
             Log.messages.Add(new KeyValuePair<MsgLevel, ErrReport>(level, msg));
             if (Log.messages.Count >= Log.msgNumberThreshold) {
                 Log.msgWaitEvent.Set();
             }
         }
     }
 }
Пример #59
0
 /// <summary>
 /// Retrieves the class and method names by reflection. Used for messages from warning to 
 /// Exception level with occur infrequently. The message is delivered by delegate for better
 /// performance when using formated error string.
 /// </summary>
 /// <param name="level">Log message level</param>
 /// <param name="code">Error code</param>
 /// <param name="msg">Error message</param>
 /// <param name="e">The exception to parse for information</param>
 private static void LogWarningAndUp(MsgLevel level, int code, Func<string> msgFunc, Exception e)
 {
     // Do the verbosity check first to avoid the overhead of reflection if it is not being logged
     if (Log.IsVerboseEnough(level)) {
         string msg = "";
         try {
             msg = msgFunc.Invoke();
         }
         catch (Exception ex) {
             msg = String.Format(
                 "Exception Thrown on invoking Msg Formater for Msg Number:{0} - {1}", code, ex.Message);
             System.Diagnostics.Debug.WriteLine(msg);
         }
         MethodBase mb = StackFrameTools.FirstNonWrappedMethod(typeof(LogUtils.Log));
         Log.LogMsg(level, code, mb.DeclaringType.Name, mb.Name, msg, e);
     }
 }
Пример #60
0
 /// <summary>
 /// Checks if the message level is equal or greater than the set verbosity
 /// </summary>
 /// <param name="msgLevel">The message level</param>
 /// <returns></returns>
 private static bool IsVerboseEnough(MsgLevel msgLevel)
 {
     // Initial check for illegal usage of Off for a message level
     if (msgLevel == MsgLevel.Off) {
         return false;
     }
     return msgLevel.GreaterOrEqual(Log.verbosity);
 }