zoukankan      html  css  js  c++  java
  • 整理的日志类

    #region 日志分类
    /// <summary>
    /// 写入日志
    /// </summary>
    /// <param name="type">日志类型</param>
    /// <param name="message">日志内容</param>
    public static void Writelog(string type, string message)
    {
    string logContent = string.Format("[{0}] =>{1}", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), message);
    //自定修改-by-wgh-2017-11-20
    Isexist();
    IsexistType(type);
    string errLogFilePath = HttpRuntime.AppDomainAppPath.ToString() + @"\Log\" + @"\\" + type + "\\" + type.Trim() + DateTime.Now.ToString("yyyyMMdd") + ".txt";
    StreamWriter sw;
    if (!File.Exists(errLogFilePath))
    {
    FileStream fs1 = new FileStream(errLogFilePath, FileMode.Create, FileAccess.Write);
    sw = new StreamWriter(fs1);
    }
    else
    {
    sw = new StreamWriter(errLogFilePath, true);
    }
    sw.WriteLine(logContent);
    sw.Flush();
    sw.Close();
    }
    #endregion

    #region 判断是否存在日志文件
    // 判断是否存在日志文件
    private static void Isexist()
    {
    // string path = Environment.CurrentDirectory + @"\Log\";//winform项目
    string path = HttpRuntime.AppDomainAppPath.ToString() + @"\Log\";//web项目
    if (!File.Exists(path))
    {
    Directory.CreateDirectory(path);
    }
    }

    private static void IsexistType(string Type)
    {
    // string path = Environment.CurrentDirectory + @"\Log\";
    string path = HttpRuntime.AppDomainAppPath.ToString() + @"\Log\" + @"\\" + Type + "\\";//web项目
    if (!File.Exists(path))
    {
    Directory.CreateDirectory(path);
    }
    }
    #endregion

    本文来自博客园,作者:.net&new,转载请注明原文链接:https://www.cnblogs.com/wugh8726254/p/7874356.html

  • 相关阅读:
    iOS基础开发集锦
    ARC&&MRC 内存管理
    iOS博客 视频课程网站
    iOS 切图规范
    ipa 重新签名
    企业证书管理
    判断是否有权限访问相机,相册,定位
    iOS 项目优化
    自定义返回按钮
    SVN 地址
  • 原文地址:https://www.cnblogs.com/wugh8726254/p/7874356.html
Copyright © 2011-2022 走看看