• c# log


    public static void WriteMsg(string logName, string msg)
            {
                try
                {
                    //string path = Path.Combine("./log");
                    string path = Application.StartupPath + "./log";
                    Directory.CreateDirectory(path);
                    string logFileName = path + "\" + DateTime.Now.ToString("yyyy-MM-dd") + ".log";//生成日志文件
                    if (!File.Exists(logFileName))//判断日志是否为当天
                    {
                        FileStream fs;
                        fs = File.Create(logFileName);//创建文件
                        fs.Close();
                    }
                    StreamWriter write = File.AppendText(logFileName);//文件中添加文件流
                    write.WriteLine(DateTime.Now.ToString()+": "+ logName + msg);
                    //write.WriteLine("----------------分割线--------------------");
                    write.Flush();
                    write.Close();
    
                }
                catch (Exception )
                {
                    string path = Path.Combine("./log");
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                        string logFileName = path + "\" + DateTime.Now.ToString("yyyy-MM-dd") + ".log";
                        if (!File.Exists(logFileName))//判断日志是否为当天
                        {
                            FileStream fs;
                            fs = File.Create(logFileName);//创建文件
                            fs.Close();
                        }
    
                        StreamWriter write = File.AppendText(logFileName);//文件中添加文件流
                        //write.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "" + logName + "
    " + msg);
                        write.WriteLine(DateTime.Now.ToString() + ": " + logName + msg);
                        // write.WriteLine("----------------分割线--------------------");
                        write.Flush();
                        write.Close();
                    }
    
                }
    
            }
    

     创建一Log类,直接类调用就可以。

  • 相关阅读:
    frida
    ES中filter 和map的使用
    阿里巴巴15 款开发者工具
    小程序的开发记录
    微信3.1小程序商城源码C# ASP.NET 多用户微商城 saas模式
    js中for,for in,forEach,for of的使用
    Vuejs学习笔记
    vue.js/element-ui/webpack 开发记录
    ESXi开启虚拟化
    shell把字符串中的字母去掉,只保留数字
  • 原文地址:https://www.cnblogs.com/gaara-zhang/p/9089534.html
Copyright © 2020-2023  润新知