using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using System.Text.RegularExpressions;
|
using System.Security.Cryptography;
|
using System.Web;
|
using System.IO;
|
|
/// <summary>
|
/// 文本日志记录辅助类
|
/// </summary>
|
public class LogTextHelper
|
{
|
static string LogFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Log");
|
public static bool RecordLog = true;
|
public static bool DebugLog = false;
|
static LogTextHelper()
|
{
|
if (!Directory.Exists(LogFolder))
|
{
|
Directory.CreateDirectory(LogFolder);
|
}
|
}
|
|
/// <summary>
|
/// 记录文本日志
|
/// </summary>
|
/// <param name="message">日志信息</param>
|
public static void WriteLine(string message)
|
{
|
string temp = DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss] ") + message + "\r\n\r\n";
|
string fileName = DateTime.Now.ToString("yyyyMMdd") + ".log";
|
try
|
{
|
if (RecordLog)
|
{
|
File.AppendAllText(Path.Combine(LogFolder, fileName), temp, Encoding.GetEncoding("GB2312"));
|
}
|
if (DebugLog)
|
{
|
Console.WriteLine(temp);
|
}
|
}
|
catch
|
{
|
}
|
}
|
|
/// <summary>
|
/// 记录文本日志
|
/// </summary>
|
/// <param name="message">日志信息</param>
|
public static void WriteLine(string fileName, string message)
|
{
|
string temp = DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss] ") + message + "\r\n\r\n";
|
//string fileName = DateTime.Now.ToString("yyyyMMdd") + ".log";
|
try
|
{
|
if (RecordLog)
|
{
|
File.AppendAllText(Path.Combine(LogFolder, fileName), temp, Encoding.GetEncoding("GB2312"));
|
}
|
if (DebugLog)
|
{
|
Console.WriteLine(temp);
|
}
|
}
|
catch
|
{
|
}
|
}
|
|
/// <summary>
|
/// 记录文本日志
|
/// </summary>
|
/// <param name="className">类名</param>
|
/// <param name="funName">方法名</param>
|
/// <param name="message">日志信息</param>
|
public static void WriteLine(string className, string funName, string message)
|
{
|
WriteLine(string.Format("{0}:{1}\r\n{2}", className, funName, message));
|
}
|
}
|