• 日志的类


    public static class LogHelper
    {
    private static string strLogFolder;
    private static string strLogFile;
    private static object _obj = new object();
    public static void CreatFile()
    {
    lock (_obj)
    {
    try
    {
    strLogFolder = Directory.GetCurrentDirectory() + "\Log";
    if (!Directory.Exists(strLogFolder))
    {
    Directory.CreateDirectory(strLogFolder);
    }
    strLogFile = strLogFolder + "\" + DateTime.Now.ToString("yy-MM-dd")+".Log";
    if (!File.Exists(strLogFile))
    {
    File.Create(strLogFile);
    }
    }
    catch (Exception ex)
    {
    throw ex;
    }

    }
    }

    public static void WriteMessage(string msg)
    {
    lock(_obj)
    {
    try
    {
    strLogFile = strLogFolder + "\" + DateTime.Now.ToString("yy-MM-dd") + ".Log";
    if (!File.Exists(strLogFile))
    {
    File.Create(strLogFile);
    }
    using (StreamWriter sw = new StreamWriter(strLogFile, true, Encoding.UTF8))
    {
    sw.Write(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + msg + " ");
    }
    }
    catch (System.Exception ex)
    {
    throw ex;
    }
    }
    }
    }

  • 相关阅读:
    Collections和Arrays常用方法
    集合(三)------双列集合
    集合(二)------单列集合
    集合(一)----------概述
    泛型
    线程
    Math类和Random类(数学公式相关类)
    时间相关的类
    Runtime类及其常用方法
    第65题:有效数字
  • 原文地址:https://www.cnblogs.com/lao-K/p/11201236.html
Copyright © 2020-2023  润新知