示例#1
0
        /// <summary>
        /// 格式化异常错误信息[控制台版这个函数理论上是线程安全的]
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static void WriteFormatExceptionLog(Exception e, string extMsg, bool showMsgBox, bool finalReport = false)
        {
            try
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.AppendFormat("应用程序出现了异常[{0}]:\r\n{1}\r\n", finalReport ? 1 : 0, e.Message);

                stringBuilder.AppendFormat("\r\n 额外信息: {0}", extMsg);
                if (null != e)
                {
                    if (e.InnerException != null)
                    {
                        stringBuilder.AppendFormat("\r\n {0}", e.InnerException.Message);
                    }
                    stringBuilder.AppendFormat("\r\n {0}", e.StackTrace);
                }

                //记录异常日志文件
                LogManager.WriteException(stringBuilder.ToString());
                if (showMsgBox)
                {
                    //弹出异常日志窗口
                    SysConOut.WriteLine(stringBuilder.ToString());
                }
            }
            catch (Exception)
            {
            }
        }
示例#2
0
        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="logType">日志类型</param>
        /// <param name="logMsg">日志信息</param>

        public static void WriteLog(LogTypes logType, string logMsg, Exception ex = null, bool bConsole = true)
        {
            if ((int)logType < (int)LogTypeToWrite) //不必记录
            {
                return;
            }

            lock (mutex)
            {
                WriteLogEx(logType, logMsg);
            }

            if (logType >= LogTypes.Fatal && bConsole)
            {
                ConsoleColor color = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;
                SysConOut.WriteLine(logMsg);
                Console.ForegroundColor = color;
            }

            if (null != ex)
            {
                WriteException(logMsg + ex.ToString());
            }
        }
示例#3
0
 public static void WriteLog(LogTypes logType, string logMsg, Exception ex = null, bool bConsole = true)
 {
     if (logType >= LogManager.LogTypeToWrite)
     {
         lock (LogManager.mutex)
         {
             LogManager.WriteLog(logType.ToString(), logMsg);
         }
         if (logType >= LogTypes.Fatal && bConsole && LogManager.LogTypeToWrite <= LogTypes.Warning)
         {
             ConsoleColor color = Console.ForegroundColor;
             Console.ForegroundColor = ConsoleColor.Red;
             SysConOut.WriteLine(logMsg);
             Console.ForegroundColor = color;
         }
         if (null != ex)
         {
             LogManager.WriteException(logMsg + ex.ToString());
         }
     }
 }