标签:
1 /// <summary> 2 /// 路径 3 /// </summary> 4 static string log = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, string.Format("DMS_{0}.log", DateTime.Today.ToString("yyyy-MM-dd"))); 5 //异常记录 6 #region 7 public static void writeLog(string logstr) 8 { 9 File.AppendAllText(log,string.Format("{0}----{1}"+Environment.NewLine,DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),logstr)); 10 } 11 #endregion 12 }
/// <summary> /// 开始执行 /// </summary> public void StartService() { try { int runTime = Convert.ToInt32(ConfigurationManager.AppSettings["frequency"].ToString()); timer = new System.Timers.Timer(runTime * 1000); timer.Elapsed += timer_Elapsed; timer.Start(); } catch (Exception ex) { Log.WriteLog(ex.Message); } } /// <summary> /// 每天执行服务相关业务操作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void timer_Elapsed(object sender, ElapsedEventArgs e) { try { Log.WriteLog("开始执行!!!!!!!!"); // 验证开始 CheckImportElectronic(); } catch (Exception ex) { Log.WriteLog(ex.Message); } }
标签:
原文地址:http://www.cnblogs.com/Mh201454/p/4176989.html