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 

  • 相关阅读:
    asp.net BS拖拽工作流设计及研发(附Demo源码)
    分享NOSQL开发实战
    jQuery插件开发实战
    asp.net搜索引擎(网络爬虫)设计及研发
    asp.net 统一认证及单点登录平台解决方案系列<一>
    ubuntu安装python的psycopg2库时报错
    记一次工作中的小坑(关于celery)
    ssh错误 IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
    使用nobody运行redis
    安装python图像处理库PIL
  • 原文地址:https://www.cnblogs.com/cyqdeshenluo/p/9253707.html
Copyright © 2011-2022 走看看