From 8f5c8891aba521570fa63c4baf616e3a3c8d9526 Mon Sep 17 00:00:00 2001
From: ulysseskao <ulysseskao@gmail.com>
Date: Sun, 01 May 2016 01:12:51 +0800
Subject: [PATCH] update for logger

---
 CCSTrace/CCS/Object/AlarmData.cs |   36 +++++++++++++++++-------------------
 1 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/CCSTrace/CCS/Object/AlarmData.cs b/CCSTrace/CCS/Object/AlarmData.cs
index 24baee3..fa1a977 100644
--- a/CCSTrace/CCS/Object/AlarmData.cs
+++ b/CCSTrace/CCS/Object/AlarmData.cs
@@ -4,25 +4,23 @@
 using System.Data.OracleClient;
 using System.Net;
 using System.Net.Sockets;
+using NLog;
 
 namespace CCSTrace.CCS.Object
 {
     public class AlarmData
     {
+        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
         private Hashtable _mTotalData = new Hashtable();
-        private RecordLog _pLog;
         private OracleConnection _connectionTpc;
         private OracleTransaction _transaction;
 
-        public AlarmData(OracleConnection conn, OracleTransaction trx, RecordLog log)
+        public AlarmData(OracleConnection conn, OracleTransaction trx)
         {
             _connectionTpc = conn;
             _transaction = trx;
-            _pLog = log;
 
-            string sqlStmt;
-
-            sqlStmt = "SELECT DEPTID,IP1,IP2,IP_PATROL FROM CCS.ALARM_IP";
+            var sqlStmt = "SELECT DEPTID,IP1,IP2,IP_PATROL FROM CCS.ALARM_IP";
             OracleCommand command = new OracleCommand(sqlStmt, _connectionTpc, _transaction);
             OracleDataReader reader = command.ExecuteReader();
 
@@ -41,7 +39,7 @@
             }
             catch (Exception e)
             {
-                _pLog.Error("Problems occur when fetch alarm data: (" + e.Message + ")");
+                Logger.Error(e, "Problems occur when fetch alarm data: (" + e.Message + ")");
                 Console.WriteLine(e.StackTrace);
             }
             finally
@@ -94,7 +92,7 @@
 
         public bool Alarm(string acceptNum, int dept)
         {
-            _pLog.Info("開始Alarm...");
+            Logger.Info("開始Alarm...");
             Socket mClient;
             ArrayList ipAddressSet = GetIpAddress(GetSscCode(dept, Convert.ToInt32(DateTime.Now.DayOfWeek)));
             string ip1;
@@ -104,14 +102,14 @@
 
             if (ipAddressSet != null)
             {
-                _pLog.Info("已取得該部門所需通知的IP Address.");
+                Logger.Info("已取得該部門所需通知的IP Address.");
                 ip1 = ipAddressSet[1].ToString();
                 ip2 = ipAddressSet[2].ToString();
                 ipPatrol = ipAddressSet[3].ToString();
             }
             else
             {
-                _pLog.Warn("無法取得該部門所需通知的IP Address!");
+                Logger.Warn("無法取得該部門所需通知的IP Address!");
                 return false;
             }
 
@@ -130,12 +128,12 @@
                 mClient.Shutdown(SocketShutdown.Both);
                 mClient.Close();
                 RecordAlarmIp(acceptNum, ip1);
-                _pLog.Info("已成功通知" + ip1 + " !");
+                Logger.Info("已成功通知" + ip1 + " !");
                 return true;
             }
             catch (Exception e)
             {
-                _pLog.Warn("無法通知" + ip1 + ": " + e.Message);
+                Logger.Warn("無法通知" + ip1 + ": " + e.Message);
             }
 
             try
@@ -153,12 +151,12 @@
                 mClient.Shutdown(SocketShutdown.Both);
                 mClient.Close();
                 RecordAlarmIp(acceptNum, ip2);
-                _pLog.Info("已成功通知" + ip2 + " !");
+                Logger.Info("已成功通知" + ip2 + " !");
                 return true;
             }
             catch (Exception e)
             {
-                _pLog.Warn("無法通知" + ip2 + ": " + e.Message);
+                Logger.Warn("無法通知" + ip2 + ": " + e.Message);
             }
 
             try
@@ -176,13 +174,13 @@
                 mClient.Shutdown(SocketShutdown.Both);
                 mClient.Close();
                 RecordAlarmIp(acceptNum, ipPatrol);
-                _pLog.Info("已成功通知" + ipPatrol + " !");
+                Logger.Info("已成功通知" + ipPatrol + " !");
                 return true;
             }
             catch (Exception e)
             {
-                _pLog.Warn("無法通知" + ipPatrol + ": " + e.Message);
-                _pLog.Warn("三個IP均無法通知到!");
+                Logger.Warn("無法通知" + ipPatrol + ": " + e.Message);
+                Logger.Warn("三個IP均無法通知到!");
                 return false;
             }
         }
@@ -196,11 +194,11 @@
             try
             {
                 if (command.ExecuteNonQuery() <= 0)
-                    _pLog.Warn("無法紀錄Alarm IP!");
+                    Logger.Warn("無法紀錄Alarm IP!");
             }
             catch (Exception e)
             {
-                _pLog.Error("recordAlarmIP Error." + e.Message);
+                Logger.Error("recordAlarmIP Error." + e.Message);
                 return;
             }
             finally

--
Gitblit v0.0.0-SNAPSHOT