zoukankan      html  css  js  c++  java
  • 记录服务日志

     protected override void OnStart(string[] args)  
            {  
                this.WriteLog(" 当前时间:" + DateTime.Now.ToString("yyyy-MM-dd hh-mm-ss") + " ");  
                this.WriteLog("客户端数据同步服务:【服务启动】");  
            }  
     
            protected override void OnStop()  
            {  
                this.WriteLog(" 当前时间:" + DateTime.Now.ToString("yyyy-MM-dd hh-mm-ss")+ " ");  
                this.WriteLog("客户端数据同步服务:【服务停止】");  
            }  
            protected override void OnShutdown()  
            {  
                this.WriteLog(" 当前时间:" + DateTime.Now.ToString("yyyy-MM-dd hh-mm-ss") + " ");  
                this.WriteLog("客户端数据同步服务:【计算机关闭】");  
            }  
    { ok = false, rst = "未能加载文件或程序集“Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。 (异常来自 HRESULT:0x80131040)" }
            #region 记录日志  
            /// <summary>  
            /// 记录日志  
            /// </summary>  
            /// <param name="msg"></param>  
            private void WriteLog(string msg)  
            {  
     
                //string path = @"C:log.txt";  
     
                //该日志文件会存在windows服务程序目录下  
                string path = AppDomain.CurrentDomain.BaseDirectory + "\log.txt";  
                FileInfo file = new FileInfo(path);  
                if (!file.Exists)  
                {  
                    FileStream fs;  
                    fs = File.Create(path);  
                    fs.Close();  
                }  
     
                using (FileStream fs = new FileStream(path, FileMode.Append, FileAccess.Write))  
                {  
                    using (StreamWriter sw = new StreamWriter(fs))  
                    {  
                        sw.WriteLine(DateTime.Now.ToString() + "   " + msg);  
                    }  
                }  
            }  
            #endregion 

  • 相关阅读:
    数字电路与系统-组合逻辑电路逻辑冒险
    数字电路与系统-组合逻辑电路竞争与冒险
    数字电路与系统-组合逻辑电路理论分析(视频)
    数字电路与系统-逻辑函数最后的总结
    微信小程序--成语猜猜看
    微信小程序开发中如何实现侧边栏的滑动效果?
    强力推荐微信小程序之简易计算器,很适合小白程序员
    【微信小程序】自定义模态框实例
    编程微刊第四期文章汇总(2018.4)
    ajax实现简单的点击左侧菜单,右侧加载不同网页
  • 原文地址:https://www.cnblogs.com/cyqdeshenluo/p/9253707.html
Copyright © 2011-2022 走看看