Exemplo n.º 1
0
 private static void WriteLog(LogStru stru)
 {
     if (LogProvider == LoggerProviersType.FILE)
     {
         File.AppendAllText(PATH, "\r\n" + string.Format("User:{0}   Date:{1}  Time:{2}  LogTypeIdentifier:{3}\nLogMessage:{4}{5}", stru.UserName, stru.DateF, stru.Time, stru.LogTypeIdentifier, stru.LogMessage, LogSeparator));
     }
     if (LogProvider == LoggerProviersType.DB)
     {
         string        sqlTemplate = " insert into tblLog values(N'{0}','{1}','{2}',N'{3}',N'{4}',N'{5}') ";
         StringBuilder sqlStr      = new StringBuilder();
         sqlStr.AppendFormat(sqlTemplate, stru.UserName.Replace("'", "\""), stru.DateF, stru.Time, stru.LogTypeIdentifier.Replace("'", "\""), stru.LogMessage.Replace("'", "\""), stru.StackTrace.Replace("'", "\""));
         IDirectDB DB = new DBHelper.SQLServer.DirectDB(DBConnection);
         DB.SQL_Log(System.Data.CommandType.Text, sqlStr.ToString());
         DB.Close();
     }
 }
Exemplo n.º 2
0
        private static void WriteExceptionLog(List <LogStru> struList)
        {
            if (LogProvider == LoggerProviersType.FILE)
            {
                StringBuilder str   = new StringBuilder();
                bool          first = true;
                foreach (LogStru stru in struList)
                {
                    string Message = stru.LogMessage;
                    string pre     = "";
                    if (!first)
                    {
                        pre     = "\t";
                        Message = "----------------------InnerException---------------------------";
                    }

                    str.AppendLine("");
                    str.AppendLine(pre + "User                :  "******"Time                :  " + stru.Time);
                    str.AppendLine(pre + "LogTypeIdentifier   :  " + stru.LogTypeIdentifier);
                    str.AppendLine(pre + "LogMessage          :  " + Message);
                    str.AppendLine(pre + "StackTrace          :\r\n" + stru.StackTrace);
                    str.AppendLine("");
                    first = false;
                }
                File.AppendAllText(PATH, str.ToString() + LogSeparator);
            }
            if (LogProvider == LoggerProviersType.DB)
            {
                string        sqlTemplate = " insert into tblLog values(N'{0}','{1}','{2}',N'{3}',N'{4}',N'{5}') ";
                StringBuilder sqlStr      = new StringBuilder();
                foreach (LogStru stru in struList)
                {
                    sqlStr.AppendFormat(sqlTemplate, stru.UserName, stru.DateF, stru.Time, stru.LogTypeIdentifier, stru.LogMessage, stru.StackTrace);
                }

                IDirectDB DB = new DBHelper.SQLServer.DirectDB(DBConnection);
                DB.SQL_Log(System.Data.CommandType.Text, sqlStr.ToString());
                DB.Close();
            }
        }