zoukankan      html  css  js  c++  java
  • C# 写日志到文件

    C# 写日志到文件

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;

    namespace psms.util
    {
        class Log
        {
            /// <summary>
            /// 写日志文件
            /// </summary>
            /// <param name="sMsg"></param>
            public static void WriteLog(string sMsg)
            {
                if (sMsg != "")
                {
                    //Random randObj = new Random(DateTime.Now.Millisecond);
                    //int file = randObj.Next() + 1;
                    string filename = DateTime.Now.ToString("yyyyMM") + ".log";
                    try
                    {
                        FileInfo fi = new FileInfo(Application.StartupPath + "\log\" + filename);
                        if (!fi.Exists)
                        {
                            using (StreamWriter sw = fi.CreateText())
                            {
                                sw.WriteLine(DateTime.Now + " " + sMsg + " ");
                                sw.Close();
                            }
                        }
                        else
                        {
                            using (StreamWriter sw = fi.AppendText())
                            {
                                sw.WriteLine(DateTime.Now + " " + sMsg + " ");
                                sw.Close();
                            }
                        }
                    }
                    catch(Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
        }
    }
  • 相关阅读:
    Android Animation学习 实现 IOS 滤镜退出动画
    Android Camera 流程梳理
    iOS启动页广告XHLaunchAd
    实现百度外卖APP个人中心头像"浪"起来的动画效果
    iOS 常用控件集合 完整项目
    Python split()分割函数Python实现源码
    Selenium RC和Selenium Webdriver环境搭建(Python)
    Python rPyc 模块应用:在远端上执行命令,并且获取查询结果
    APP UI设计相关的一些链接
    IOS 开发的官方文档链接
  • 原文地址:https://www.cnblogs.com/Xujg/p/3823525.html
Copyright © 2011-2022 走看看