⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 log.cs

📁 《C#和.NET第一步》中的财务系统 利用三层结构做的
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace Common
{
	public class Logger
	{

		public static void Log(Exception e)
		{
			try
			{
				//构造日志文件,每天一个
				DateTime dt = DateTime.Now;
				string file = "log_" + dt.ToString("yyyy-MM-dd") + ".txt";
				StreamWriter sw = new StreamWriter(file, true);
				try
				{
					sw.WriteLine(dt.ToShortTimeString());
					sw.WriteLine(e.ToString());
					sw.WriteLine();
				}
				finally
				{
					sw.Close();
				}
			}
			catch
			{	
			}
		}
		public static void Log(string  str)
		{
			try
			{
				//构造日志文件,每天一个
				DateTime dt = DateTime.Now;
				string file = "log_" + dt.ToString("yyyy-MM-dd") + ".txt";
				StreamWriter sw = new StreamWriter(file, true);
				try
				{
					sw.WriteLine(dt.ToShortTimeString());
					sw.WriteLine(str);
					sw.WriteLine();
				}
				finally
				{
					sw.Close();
				}
			}
			catch
			{
			}
		}
	}
}

⌨️ 快捷键说明

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