示例#1
0
        /// <summary>
        /// 寫入LOG
        /// </summary>
        /// <param name="FunctionName">模組+功能代號</param>
        /// <param name="RS">OK:成功,NG:失敗</param>
        /// <param name="StepStr">步驟</param>
        public void LogAdd(string FunctionName,
                           bool ResultStatus,
                           string StepStr
                           )
        {
            LogHelper LH = new LogHelper(ConnectionDB);

            ArrayList ParameterList = new ArrayList();

            ParameterList.Add(1);
            ParameterList.Add(FunctionName);
            ParameterList.Add((ResultStatus) ? "OK" : "NG");
            ParameterList.Add(StepStr);

            LH.WriteApLog(ParameterList, null);

        }
示例#2
0
        /// <summary>
        /// 寫入Waring Log
        /// </summary>
        /// <param name="MessageStr">傳入訊息</param>
        public void WaringLogProcess(string MessageStr)
        {
            string URLStr = Request.ServerVariables["URL"].ToString();
            string[] WebSite = URLStr.Split('/');//位置2為小模組目錄名稱

            XmlDocument xdoc = new XmlDocument();            
            string LogSettingFilePathAndName = string.Format("{0}/{1}",
                                                             Application["Config_Path"].ToString(),
                                                             LogSettingFile
                                                             );

            xdoc.Load(LogSettingFilePathAndName);

            XmlNodeList RootNodeList = xdoc.SelectNodes("ProcessFile/add");



            for (int i = 0; i < RootNodeList.Count; i++)
            {
                string ProcessFile = RootNodeList[i].Attributes["File"].Value;
                SYSModel.LogLevel LogLevelProc = (SYSModel.LogLevel)int.Parse(RootNodeList[i].Attributes["LogLevel"].Value);

                if (((ProcessFile == "*") && (LogLevelProc >= SYSModel.LogLevel.Waring)) ||
                     ((ProcessFile == this.PageCode + ".aspx") && (LogLevelProc >= SYSModel.LogLevel.Waring))
                    )
                {
                    SYSModel.LogHelper ProcLog = new SYSModel.LogHelper(ConnectionDB);

                    ParameterList.Clear();

                    //Server名稱
                    ParameterList.Add(Request.ServerVariables["Server_Name"]);
                    //模組名稱
                    ParameterList.Add(WebSite[2]);
                    //URL
                    ParameterList.Add(Request.Path);
                    //LOGLEVEL
                    ParameterList.Add(SYSModel.LogLevel.Waring);
                    //錯誤訊息
                    ParameterList.Add(MessageStr);
                    //控制項內容
                    ParameterList.Add("");
                    //SQL語法
                    ParameterList.Add("");
                    try
                    {
                        //使用者
                        ParameterList.Add(Session["UID"].ToString());
                    }
                    catch (Exception ex)
                    {
                        //使用者
                        ParameterList.Add("SessionUID Timeout");
                    }

                    PerformanceCounter PC = new PerformanceCounter();
                    PerformanceCounter PC1 = new PerformanceCounter();
                    try
                    {
                        //目前記憶體總量
                        PC.CategoryName = PerformanceCounter_TotalMemoryCategoryName;
                        PC.CounterName = PerformanceCounter_TotalMemoryCounterName;
                        PC.InstanceName = PerformanceCounter_TotalMemoryInstanceName;
                        PC.ReadOnly = true;

                        ParameterList.Add(PC.NextValue());

                    }
                    catch (Exception ex)
                    {
                        ParameterList.Add(-1);
                    }
                    finally
                    {
                        try
                        {
                            //未釋放的記憶體
                            PC1.CategoryName = PerformanceCounter_HeapMemoryCategoryName;
                            PC1.CounterName = PerformanceCounter_HeapMemoryCounterName;
                            PC1.InstanceName = PerformanceCounter_HeapMemoryInstanceName;
                            PC1.ReadOnly = true;

                            ParameterList.Add(PC1.NextValue());
                        }
                        catch (Exception ex)
                        {
                            ParameterList.Add(-1);
                        }
                        finally
                        {
                            //檢查變數項目是否足夠
                            ParameterListIndexCheck(WebSite[2],
                                                    SYSModel.LogLevel.Waring,
                                                    ""
                                                    );

                            //寫入DB
                            ProcLog.WriteLog(ParameterList,
                                             null
                                             );

                            PC.Close();

                            PC1.Close();
                        }

                    }

                }
            }
        }
示例#3
0
        /// <summary>
        /// 寫入Information Log
        /// </summary>
        private void InformationLogProcess()
        {
            string URLStr = Request.ServerVariables["URL"].ToString();
            string[] WebSite = URLStr.Split('/');//位置2為小模組目錄名稱

            //Config存放路徑
            //string ConfigFilePath = Server.MapPath("/" + WebSite[1] + "/Config/");
            //string LogFilePath = Server.MapPath("/" + WebSite[1] + "/LOG");

            XmlDocument xdoc = new XmlDocument();            
            string LogSettingFilePathAndName = string.Format("{0}/{1}",
                                                             Application["Config_Path"].ToString(),
                                                             LogSettingFile
                                                             );

            xdoc.Load(LogSettingFilePathAndName);

            XmlNodeList RootNodeList = xdoc.SelectNodes("ProcessFile/add");



            for (int i = 0; i < RootNodeList.Count; i++)
            {
                string ProcessFile = RootNodeList[i].Attributes["File"].Value;
                SYSModel.LogLevel LogLevelProc = (SYSModel.LogLevel)int.Parse(RootNodeList[i].Attributes["LogLevel"].Value);                

                //如果所有程式或特定程式的Log等級設為Information
                if ( (( ProcessFile== "*") && (LogLevelProc == SYSModel.LogLevel.Information))  ||
                     (( ProcessFile== this.PageCode+".aspx") && (LogLevelProc == SYSModel.LogLevel.Information))
                    )

                {
                    SYSModel.LogHelper ProcLog = new SYSModel.LogHelper(ConnectionDB);
                    
                    SYSModel.RequestStruct[] Rqs = new SYSModel.RequestStruct[Request.Form.Count];

                    StringBuilder sb = new StringBuilder();

                    sb.Remove(0, sb.Length);

                    for (int j=0;j<Rqs.Length;j++)
                    {
                        //Rqs[j].ControlID = Request.Form.GetKey(j);
                        //Rqs[j].Value = Request.Form.GetValues(j)[0].ToString(); ;
                        sb.AppendFormat("控制項名稱:{0},內容{1};",
                                        Request.Form.GetKey(j).ToString(),
                                        Request.Form.GetValues(j)[0].ToString()
                                        );
                    }

                    ParameterList.Clear();

                    //Server名稱
                    ParameterList.Add(Request.ServerVariables["Server_Name"]);
                    //模組名稱
                    ParameterList.Add(WebSite[2]);
                    //URL
                    ParameterList.Add(Request.Path);
                    //LOGLEVEL
                    ParameterList.Add(SYSModel.LogLevel.Information);
                    //錯誤訊息
                    ParameterList.Add("紀錄Information");
                    //控制項內容
                    ParameterList.Add(sb.ToString());
                    //SQL語法
                    ParameterList.Add("");
                    try
                    {
                        //使用者
                        ParameterList.Add(Session["UID"].ToString());
                    }
                    catch (Exception ex)
                    {
                        //使用者
                        ParameterList.Add("SessionUID Timeout");
                    }

                    PerformanceCounter PC = new PerformanceCounter();
                    PerformanceCounter PC1 = new PerformanceCounter();
                    try
                    {
                        //目前記憶體總量
                        PC.CategoryName = PerformanceCounter_TotalMemoryCategoryName;
                        PC.CounterName = PerformanceCounter_TotalMemoryCounterName;
                        PC.InstanceName = PerformanceCounter_TotalMemoryInstanceName;                                                                       
                        PC.ReadOnly = true;                                                                       

                        ParameterList.Add(PC.NextValue());
                        
                    }
                    catch (Exception ex)
                    {
                        ParameterList.Add(-1);
                    }
                    finally
                    {
                        try
                        {
                            //未釋放的記憶體
                            PC1.CategoryName = PerformanceCounter_HeapMemoryCategoryName;
                            PC1.CounterName = PerformanceCounter_HeapMemoryCounterName;
                            PC1.InstanceName = PerformanceCounter_HeapMemoryInstanceName;
                            PC1.ReadOnly = true;

                            ParameterList.Add(PC1.NextValue());
                        }
                        catch (Exception ex)
                        {
                            ParameterList.Add(-1);
                        }
                        finally
                        {
                            //檢查變數項目是否足夠
                            ParameterListIndexCheck(WebSite[2],
                                                    SYSModel.LogLevel.Information,
                                                    sb.ToString()
                                                    );

                            //寫入DB
                            ProcLog.WriteLog(ParameterList,
                                             null
                                             );

                            PC.Close();

                            PC1.Close();
                        }

                    }

                }
            }
            
            
        }