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  
  • 相关阅读:
    【zookeeper】
    关于redis-windows环境下的一些配置:
    mybatis-注解开发
    jQuery的Validate插件
    Thymeleaf 学习笔记-实例demo(中文教程)
    thymeleaf 学习笔记-基础篇(中文教程)
    AGC 043C
    JOISC 2020 部分题解
    Loj #2687
    CF 1270I
  • 原文地址:https://www.cnblogs.com/cyqdeshenluo/p/7866229.html
Copyright © 2011-2022 走看看