码迷,mamicode.com
首页 > 其他好文 > 详细

简洁的写日志发短信

时间:2018-02-09 20:41:13      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:factory   factor   one   body   void   err   出现   class   pos   

 

  以后写日志,发短信什么的,统一集合到一份!虽然代码超简单。但是我的思维总是不够面向对象,写代码如果感觉到了麻烦,就要考虑方式了。

提醒我这个猪脑子。。。

  

    private static void monitoring()
        {
            //监控是否有数据
            //监控是否有数据
            var strbuilder = new StringBuilder();
            var networkerrorbuilder = new StringBuilder();
            networkerrorbuilder = null;
            for (int i = 0; i < FactoryID.Length; i++)
            {
                string plant="";
                try
                {
                    int ID = int.Parse(FactoryID[i]);
                    string sql = "select COUNT(*) from Realtime5.dbo.Web_HistoryData with(nolock) where FactoryId=" + ID + " and datediff(HOUR, DateTime,GETDATE())<=1";
                    int count = int.Parse(SqlHelper.SelectCounts(sql));
                    string sqlplant = "select fname  from PMIS5.dbo.Sys_Factorys with(nolock) where fid=" + ID + "";
                    plant = SqlHelper.SelectCounts(sqlplant);
                    if (count <= 0)
                    {
                        strbuilder.Append(plant+ ",");    
                    }
                }

                catch (Exception ex)
                {
                    networkerrorbuilder.Append(plant + ",");
                }

            }

            // if have result,to send
            if (!string.IsNullOrEmpty(strbuilder.ToString()) || !string.IsNullOrEmpty(networkerrorbuilder.ToString()))
            {
                if (networkerrorbuilder == null)
                {
                    SendSmsHelper.SendSms(strPhone, strbuilder.ToString() + "的Web_History表近一个小时数据为空;");
                    Log.Save(strbuilder.ToString() + "的Web_History表近一个小时数据为空");
                }
                else
                {
                    SendSmsHelper.SendSms(strPhone, strbuilder.ToString() + "的Web_History表近一个小时数据为空;" + "\r\n" + networkerrorbuilder.ToString() + "的网络出现故障");
                    Log.Save(strbuilder.ToString() + "的Web_History表近一个小时数据为空" + networkerrorbuilder.ToString() + "的网络出现故障");
                }
                
            }
         
        }
    }

 

简洁的写日志发短信

标签:factory   factor   one   body   void   err   出现   class   pos   

原文地址:https://www.cnblogs.com/yunquan/p/8436066.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!