protected override void OnStop() { StringBuilder log = new StringBuilder(); log.AppendLine("\n当前时间:" + DateTime.Now.ToString() + " 服务关闭...\n"); LogFileOperator.writeLog(log.ToString()); }
/** * 入口程序 * */ public static void work(object sender, ElapsedEventArgs args) { //检查日志 LogFileOperator.check(); //执行文件删除 string log = Cleaner.cleanUpExcessFiles(GlobleParams.getConfigList(), GlobleParams.getDeletePercent()); //写日志 LogFileOperator.writeLog(log); }
private static void printGlobleParams() { StringBuilder log = new StringBuilder(); log.AppendLine("当前时间:" + DateTime.Now.ToString() + " 服务启动...\n"); log.AppendLine("执行频率:" + GlobleParams.getFrequency() / 60000 + "分钟"); log.AppendLine("删除比例:" + GlobleParams.getDeletePercent() + "%"); log.AppendLine("共读取到:" + GlobleParams.getConfigList().Count() + "个需要检查的路径\n"); LogFileOperator.writeLog(log.ToString()); }
protected override void OnStart(string[] args) { //检查配置文件是否存在,若不存在则创建 ConfigChecker.check(); //读取配置文件并初始化全局变量 ConfigReader.read(); //检查日志文件 LogFileOperator.check(); //在日志中输出启动信息 printGlobleParams(); //执行定时清理文件任务 startTimeJob(); }