log.cs
来自「《C#和.NET第一步》中的财务系统 利用三层结构做的」· CS 代码 · 共 58 行
CS
58 行
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 + =
减小字号Ctrl + -
显示快捷键?