Exemple #1
0
        /// <summary>
        /// 2016-07-19 08:50:25 ngocta2
        /// chi log hanh dong AddItemToSortedSet
        /// Z_KEY, Z_VALUE, Z_SCORE
        ///Log(CConfig.BASE_LOG_PATH_TEXT, strTitle, strDetail);
        ///<!-- C:\Log\MyApp\TEXT\2014\05\17\1gzjxwqq.p0b   |  C:\Log\MyApp\TEXT\2014-05-17.txt -->
        ///<add key="BASE_LOG_PATH_TEXT" value="C:\Log\(AppName)\TEXT\(yyyy)\(MM)\(dd)\" />
        ///<!-- C:\Log\MyApp\TYPE\2014\05\17\1_SECURITY_14_22_59__1gzjxwqq.txt -->
        ///<add key="BASE_LOG_PATH_EX" value="C:\Log\(AppName)\LogEx\(yyyy)\(MM)\(dd)\(FileName)" />
        ///15:21:34.843^20160719090544764^{"Time":"09:05:44","Data":{"TimeJS":"1468893900000","Index":"86.99","Vol":"111500"}}
        /// </summary>
        /// <param name="strFileNameEx"></param>
        /// <param name="strBody"></param>
        public static void LogRedis(string strZKey, double dblZScore, string strZValue)
        {
            try
            {
                string strPath = CConfig.BASE_LOG_PATH_TEXT
                                 .Replace("(AppName)", CConfig.BASE_APP_NAME)
                                 .Replace("(yyyy)", DateTime.Now.Year.ToString())
                                 .Replace("(MM)", CBase.Right("00" + DateTime.Now.Month.ToString(), 2))
                                 .Replace("(dd)", CBase.Right("00" + DateTime.Now.Day.ToString(), 2));

                // check folder
                CheckDirectory(strPath);

                // noi them filename, chu y error
                //LE:S5G_ACM => error
                strPath += strZKey.Replace(":", "___") + ".js";

                // tao body
                string strBody = Convert.ToInt64(dblZScore).ToString() + "^" + strZValue;

                // write
                StreamWriter fs = new StreamWriter(strPath, true); // append
                //15:21:34.843^20160719090544764^{"Time":"09:05:44","Data":{"TimeJS":"1468893900000","Index":"86.99","Vol":"111500"}}
                fs.WriteLine(DateTime.Now.ToString("HH:mm:ss.") + DateTime.Now.Millisecond.ToString("000") + "^" + strBody);
                fs.Close();
            }
            catch (Exception)
            {
                // do nothing
            }
            finally
            {
            }
        }
Exemple #2
0
        /// <summary>
        /// 2015-05-04 14:32:33 ngocta2
        /// </summary>
        /// <param name="strFullPathTemplate"></param>
        /// <param name="strBody"></param>
        /// <param name="blnIsAppend"></param>
        public static void WriteFile(string strFullPathTemplate, string strBody, bool blnIsAppend)
        {
            try
            {
                // C:\Log\5G_QuoteFeeder_HOSE\SQL\2014_12_04.txt
                string strPath = strFullPathTemplate
                                 .Replace("(AppName)", CConfig.BASE_APP_NAME)
                                 .Replace("(yyyy)", DateTime.Now.Year.ToString())
                                 .Replace("(MM)", CBase.Right("00" + DateTime.Now.Month.ToString(), 2))
                                 .Replace("(dd)", CBase.Right("00" + DateTime.Now.Day.ToString(), 2))
                ;

                // check folder
                CheckDirectory(strPath);

                // write
                StreamWriter fs = new StreamWriter(strPath, blnIsAppend); // append
                fs.WriteLine(strBody);
                fs.Close();
            }
            catch (Exception)
            {
                // do nothing
            }
            finally
            {
            }
        }
Exemple #3
0
        /// <summary>
        /// 2015-05-04 14:41:33 ngocta2
        /// chi can read 1 dong
        /// </summary>
        /// <param name="strFullPathTemplate"></param>
        /// <returns></returns>
        public static string ReadFile(string strFullPathTemplate)
        {
            try
            {
                // C:\Log\5G_QuoteFeeder_HOSE\SQL\2014_12_04.txt
                string strPath = strFullPathTemplate
                                 .Replace("(AppName)", CConfig.BASE_APP_NAME)
                                 .Replace("(yyyy)", DateTime.Now.Year.ToString())
                                 .Replace("(MM)", CBase.Right("00" + DateTime.Now.Month.ToString(), 2))
                                 .Replace("(dd)", CBase.Right("00" + DateTime.Now.Day.ToString(), 2))
                ;

                // check folder
                CheckDirectory(strPath);

                // read
                string strBody = "";
                using (StreamReader sr = new StreamReader(strPath))
                {
                    strBody = sr.ReadToEnd();
                }

                return(strBody);
            }
            catch (Exception)
            {
                // do nothing
                return("");
            }
            finally
            {
            }
        }
Exemple #4
0
        /// <summary>
        /// 2018-08-27 10:50:47 ngocta2
        /// Log2() chi tiet hon Log()
        /// </summary>
        /// <param name="strPathTemplate">D:\WebLog\(AppName)\SQL\(yyyy)\(MM)\(dd)\</param>
        /// <param name="strTitle">TransferHist</param>
        /// <param name="strDetail">SQL script...</param>
        /// <param name="strAccountNo">058C108101 | Api_Transfer_Next_Working_Day</param>
        /// <param name="strExt">.sql</param>
        private static void Log2(string strPathTemplate, string strTitle, string strDetail, string strAccountNo, string strExt)
        {
            try
            {
                string strPath     = strPathTemplate.Replace("(AppName)", CConfig.BASE_APP_NAME);
                string strLine     = "";
                string strFileName = strAccountNo;

                // full path = strPath + strFileName + "." + strExt

                if (CConfig.BASE_LOG_MULTI_THREAD != CConfig.SINGLE_THREAD)
                {
                    // multi - ko duoc write chung 1 file - error "file locked by other process"
                    strPath = strPath
                              .Replace("(yyyy)", DateTime.Now.Year.ToString())
                              .Replace("(MM)", CBase.Right("00" + DateTime.Now.Month.ToString(), 2))
                              .Replace("(dd)", CBase.Right("00" + DateTime.Now.Day.ToString(), 2));
                    strPath += Path.GetRandomFileName();
                }
                else
                {
                    // single
                    //strPath = strPath.Replace("(yyyy)\\(MM)\\(dd)\\", "(yyyy)-(MM)-(dd)");
                    strPath = strPath
                              .Replace("(yyyy)", DateTime.Now.Year.ToString())
                              .Replace("(MM)", CBase.Right("00" + DateTime.Now.Month.ToString(), 2))
                              .Replace("(dd)", CBase.Right("00" + DateTime.Now.Day.ToString(), 2));
                    strPath += strFileName + strExt; // D:\WebLog\DataService\SQL\2018\08\27\058C108101.sql | D:\WebLog\DataService\SQL\2018\08\27\Api_Transfer_Next_Working_Day.sql
                }


                // data
                strLine = CConfig.TEMPLATE_LOG_DATA
                          .Replace("(Time)", DateTime.Now.ToString("HH:mm:ss.") + DateTime.Now.Millisecond.ToString("000"))
                          .Replace("(Title)", strTitle)
                          .Replace("(Detail)", strDetail);

                // check folder
                CheckDirectory(strPath);

                // remove password text
                strLine = Regex.Replace(strLine, "(p_aOldPass|p_aNewPass|p_aOldTradePass|p_aNewTradePass|p_apassword)='(.*?)'", "$1='******'");

                // write
                StreamWriter fs = new StreamWriter(strPath, true); // append
                fs.WriteLine(strLine);
                fs.Close();
            }
            catch (Exception)
            {
                // do nothing
            }
            finally
            {
            }
        }
Exemple #5
0
        /// <summary>
        /// ghi log file
        /// </summary>
        /// <param name="strPathTemplate"></param>
        /// <param name="str1"></param>
        /// <param name="str2"></param>
        private static void Log(string strPathTemplate, string str1, string str2)
        {
            try
            {
                string strPath = strPathTemplate.Replace("(AppName)", CConfig.BASE_APP_NAME);
                string strLine = "";

                if (CConfig.BASE_LOG_MULTI_THREAD != CConfig.SINGLE_THREAD)
                {
                    // multi - ko duoc write chung 1 file - error "file locked by other process"
                    strPath = strPath
                              .Replace("(yyyy)", DateTime.Now.Year.ToString())
                              .Replace("(MM)", CBase.Right("00" + DateTime.Now.Month.ToString(), 2))
                              .Replace("(dd)", CBase.Right("00" + DateTime.Now.Day.ToString(), 2));
                    strPath += Path.GetRandomFileName();
                }
                else
                {
                    // single
                    strPath = strPath.Replace("(yyyy)\\(MM)\\(dd)\\", "(yyyy)-(MM)-(dd)");
                    strPath = strPath
                              .Replace("(yyyy)", DateTime.Now.Year.ToString())
                              .Replace("(MM)", CBase.Right("00" + DateTime.Now.Month.ToString(), 2))
                              .Replace("(dd)", CBase.Right("00" + DateTime.Now.Day.ToString(), 2));
                    strPath += CConfig.LOG_EXT;
                }


                // data
                strLine = CConfig.TEMPLATE_LOG_DATA
                          .Replace("(Time)", DateTime.Now.ToString("HH:mm:ss.") + DateTime.Now.Millisecond.ToString("000"))
                          .Replace("(Title)", str1)
                          .Replace("(Detail)", str2);

                // check folder
                CheckDirectory(strPath);

                // write
                StreamWriter fs = new StreamWriter(strPath, true); // append
                fs.WriteLine(strLine);
                fs.Close();
            }
            catch (Exception)
            {
                // do nothing
            }
            finally
            {
            }
        }
Exemple #6
0
        /// <summary>
        /// 2017-11-02 15:54:57 ngocta2
        /// ghi data vao file de co luc load lai, ko ghi cac moc time (de debug) vao trong noi dung file
        /// su dung chung folder LogEx
        /// </summary>
        /// <param name="strFileName"></param>
        /// <param name="strData"></param>
        /// <returns></returns>
        public static string LogDataSave(string strFileName, string strData)
        {
            try
            {
                lock (m_objLocker)
                {
                    // D:\LOG\StockHNX2\LogEx\2017\11\02\BASKET_HNX.js
                    string strPath = CConfig.BASE_LOG_PATH_EX
                                     .Replace("(AppName)", CConfig.BASE_APP_NAME)
                                     .Replace("(yyyy)", DateTime.Now.Year.ToString())
                                     .Replace("(MM)", CBase.Right("00" + DateTime.Now.Month.ToString(), 2))
                                     .Replace("(dd)", CBase.Right("00" + DateTime.Now.Day.ToString(), 2))
                                     .Replace("(FileName)", strFileName)
                    ;

                    // check folder
                    CheckDirectory(strPath);

                    // neu noi dung ko co gi thi chi lay path (ko write)
                    if (strData == "")
                    {
                        return(strPath);
                    }

                    // neu file ton tai thi xoa truoc khi write
                    if (File.Exists(strPath))
                    {
                        File.Delete(strPath);
                    }

                    // write
                    StreamWriter fs = new StreamWriter(strPath, true); // append
                    fs.WriteLine(strData);
                    fs.Close();

                    // return path
                    return(strPath);
                }
            }
            catch (Exception)
            {
                // do nothing
                return("");
            }
            finally
            {
            }
        }
Exemple #7
0
        /// <summary>
        /// tuong tu LogEx
        /// </summary>
        /// <param name="strFileNameEx"></param>
        /// <param name="strBody"></param>
        /// <param name="arrHeader"></param>
        public static void LogCSV(string strFileNameEx, string strBody, string[] arrHeader)
        {
            try
            {
                // C:\Log\5G_QuoteFeeder_HOSE\SQL\2014\12\04\1__security__14_34_59__afj43laf.txt
                string strPath = CConfig.BASE_LOG_PATH_EX
                                 .Replace("(AppName)", CConfig.BASE_APP_NAME)
                                 .Replace("(yyyy)", DateTime.Now.Year.ToString())
                                 .Replace("(MM)", CBase.Right("00" + DateTime.Now.Month.ToString(), 2))
                                 .Replace("(dd)", CBase.Right("00" + DateTime.Now.Day.ToString(), 2))
                                 .Replace("(FileName)", strFileNameEx)
                ;

                // check folder
                CheckDirectory(strPath);

                // tao row header neu file chua ton tai
                string strHeader = "";
                if (!File.Exists(strPath))
                {
                    strHeader = "Time";
                    foreach (string str in arrHeader)
                    {
                        strHeader += "," + str;
                    }
                }

                // write
                StreamWriter fs = new StreamWriter(strPath, true); // append
                if (strHeader != "")
                {
                    fs.WriteLine(strHeader);
                }
                fs.WriteLine(DateTime.Now.ToString("HH:mm:ss.") + DateTime.Now.Millisecond.ToString("000") + "," + strBody);
                fs.Close();
            }
            catch (Exception)
            {
                // do nothing
            }
            finally
            {
            }
        }
Exemple #8
0
        /// <summary>
        /// log cao cap, chi tiet hon: thuong dung de log cac du lieu big, phai chia nho file nhu log SQL (single file = 800MB)
        /// 1 file chi ghi 1 lan, ko ghi nhieu lan (nhieu line) trong 1 file
        /// <add key="BASE_LOG_PATH_EX"       value="C:\Log\(AppName)\(Type)\(yyyy)\(MM)\(dd)\(FileName).txt" />
        /// <add key="BASE_TEMPLATE_LOG_EX_FILENAME"      value="(thread)__(type)__(hh)_(mm)_(ss)__(random).txt" />
        /// </summary>
        /// <param name="strFolder">SQL/ERROR/TEXT</param>
        /// <param name="strFileNameEx">1_security_14_33_59_afj43laf</param>
        /// <param name="strBody">SQL script</param>
        public static string LogEx(string strFileNameEx, string strBody)
        {
            try
            {
                lock (m_objLocker)
                {
                    // C:\Log\5G_QuoteFeeder_HOSE\SQL\2014\12\04\1__security__14_34_59__afj43laf.txt
                    string strPath = CConfig.BASE_LOG_PATH_EX
                                     .Replace("(AppName)", CConfig.BASE_APP_NAME)
                                     .Replace("(yyyy)", DateTime.Now.Year.ToString())
                                     .Replace("(MM)", CBase.Right("00" + DateTime.Now.Month.ToString(), 2))
                                     .Replace("(dd)", CBase.Right("00" + DateTime.Now.Day.ToString(), 2))
                                     .Replace("(FileName)", strFileNameEx)
                    ;

                    // check folder
                    CheckDirectory(strPath);

                    // neu noi dung ko co gi thi chi lay path (ko write)
                    if (strBody == "")
                    {
                        return(strPath);
                    }

                    // write
                    StreamWriter fs = new StreamWriter(strPath, true); // append
                    fs.WriteLine(DateTime.Now.ToString("HH:mm:ss.") + DateTime.Now.Millisecond.ToString("000") + " => " + strBody);
                    fs.Close();

                    //
                    return(strPath);
                }
            }
            catch (Exception)
            {
                // do nothing
                return("");
            }
            finally
            {
            }
        }
Exemple #9
0
 //<add key="BASE_TEMPLATE_LOG_EX_FILENAME"      value="(thread)__(type)__(hh)_(mm)_(ss)__(random).(ext)" />
 //"1__security__14_33_55__abcd7890"
 //CLog.LogEx("TEST", "1__security__14_33_55__abcd7890", "Tạm ứng cổ tức năm đợt 2 năm 2014 bằng tiền mặt, 2.000đồng/cổ phiếu");
 public static string GetLogExFileName(int intThread, string strType, string strExt)
 {
     try
     {
         string strFileName = CConfig.BASE_TEMPLATE_LOG_EX_FILENAME;
         strFileName = strFileName
                       .Replace("(thread)", intThread.ToString())
                       .Replace("(type)", strType)
                       .Replace("(hh)", CBase.Right("00" + DateTime.Now.Hour.ToString(), 2))
                       .Replace("(mm)", CBase.Right("00" + DateTime.Now.Minute.ToString(), 2))
                       .Replace("(ss)", CBase.Right("00" + DateTime.Now.Second.ToString(), 2))
                       .Replace("(random)", System.IO.Path.GetRandomFileName())
                       .Replace("(ext)", strExt);
         return(strFileName);
     }
     catch (Exception ex)
     {
         CLog.LogError(CBase.GetDeepCaller(), CBase.GetDetailError(ex));
         return("");
     }
 }
Exemple #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="strFileName"></param>
        /// <returns></returns>
        public static string LogDataLoad(string strFileName)
        {
            try
            {
                lock (m_objLocker)
                {
                    // D:\LOG\StockHNX2\LogEx\2017\11\02\BASKET_HNX.js
                    string strPath = CConfig.BASE_LOG_PATH_EX
                                     .Replace("(AppName)", CConfig.BASE_APP_NAME)
                                     .Replace("(yyyy)", DateTime.Now.Year.ToString())
                                     .Replace("(MM)", CBase.Right("00" + DateTime.Now.Month.ToString(), 2))
                                     .Replace("(dd)", CBase.Right("00" + DateTime.Now.Day.ToString(), 2))
                                     .Replace("(FileName)", strFileName)
                    ;

                    // check folder
                    CheckDirectory(strPath);

                    // read
                    string strData = "";
                    using (StreamReader sr = new StreamReader(strPath))
                    {
                        strData = sr.ReadToEnd();
                    }

                    return(strData);
                }
            }
            catch (Exception)
            {
                // do nothing
                return("");
            }
            finally
            {
            }
        }