|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
namespace AKSWebBrowser.Commen
|
|
|
|
{
|
|
|
|
public class Log
|
|
|
|
{
|
|
|
|
private static StreamWriter streamWriter; //写文件
|
|
|
|
|
|
|
|
public static void Error(string message)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
//DateTime dt = new DateTime();
|
|
|
|
string directPath = AppDomain.CurrentDomain.BaseDirectory + @"/logs/error"; //在获得文件夹路径
|
|
|
|
if (!Directory.Exists(directPath)) //判断文件夹是否存在,如果不存在则创建
|
|
|
|
{
|
|
|
|
Directory.CreateDirectory(directPath);
|
|
|
|
}
|
|
|
|
directPath += string.Format(@"/{0}.log", DateTime.Now.ToString("yyyy-MM-dd"));
|
|
|
|
if (streamWriter == null)
|
|
|
|
{
|
|
|
|
streamWriter = !File.Exists(directPath) ? File.CreateText(directPath) : File.AppendText(directPath);
|
|
|
|
}
|
|
|
|
if (streamWriter != null)
|
|
|
|
{
|
|
|
|
streamWriter.WriteLine("***********************************************************************");
|
|
|
|
streamWriter.WriteLine(DateTime.Now.ToString("HH:mm:ss"));
|
|
|
|
streamWriter.WriteLine("输出信息:错误信息");
|
|
|
|
streamWriter.WriteLine("异常信息:\r\n" + message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch { }
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (streamWriter != null)
|
|
|
|
{
|
|
|
|
streamWriter.Flush();
|
|
|
|
if (streamWriter != null)
|
|
|
|
{
|
|
|
|
streamWriter.Dispose();
|
|
|
|
streamWriter = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception) { }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Info(string message)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
//DateTime dt = new DateTime();
|
|
|
|
string directPath = AppDomain.CurrentDomain.BaseDirectory + @"/logs/Info"; //在获得文件夹路径
|
|
|
|
if (!Directory.Exists(directPath)) //判断文件夹是否存在,如果不存在则创建
|
|
|
|
{
|
|
|
|
Directory.CreateDirectory(directPath);
|
|
|
|
}
|
|
|
|
directPath += string.Format(@"/{0}.log", DateTime.Now.ToString("yyyy-MM-dd"));
|
|
|
|
if (streamWriter == null)
|
|
|
|
{
|
|
|
|
try { streamWriter = !File.Exists(directPath) ? File.CreateText(directPath) : File.AppendText(directPath); } catch { } finally { }
|
|
|
|
}
|
|
|
|
if (streamWriter != null)
|
|
|
|
{
|
|
|
|
streamWriter.WriteLine("***********************************************************************");
|
|
|
|
streamWriter.WriteLine(DateTime.Now.ToString("HH:mm:ss"));
|
|
|
|
streamWriter.WriteLine("输出信息:Info信息");
|
|
|
|
streamWriter.WriteLine("Info信息:\r\n" + message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch { }
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (streamWriter != null)
|
|
|
|
{
|
|
|
|
streamWriter.Flush();
|
|
|
|
if (streamWriter != null)
|
|
|
|
{
|
|
|
|
streamWriter.Dispose();
|
|
|
|
streamWriter = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception) { }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|