logger.cs

来自「不错的一个做的医院管理系统源码」· CS 代码 · 共 59 行

CS
59 行
字号
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Youzi.DBUtility
{
    public class Logger
    {
        
        
        public Logger()
        {
            StreamWriter sw = null;
            try
            {
                string d = DateTime.Now.ToString("yyyy年MM月dd日");
                string path = Application.StartupPath;
                if (File.Exists(path + "\\" + d + ".log"))
                {
                    sw = new StreamWriter(path + "\\" + d + ".log"); 
                       
                }
                else
                {
                    sw = File.CreateText(path + "\\" + d + ".log");
                }
            }
            catch (SqlException ex)
            {

                Console.WriteLine(ex.Message);
            }
            sw.Close();
        }

        public void log(String message)
        {
            StreamWriter sw = null;
            try
            {
                string d = DateTime.Now.ToString("yyyy年MM月dd日 hh:mm:ss");
                sw.WriteLine(d + ":" + message);
                sw.Flush();
            }
            catch (SqlException ex)
            {

                 Console.WriteLine(ex.Message);
            }
            sw.Close();
        }

    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?