|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
namespace DevicesService.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);
|
|
|
|
}
|
|
|
|
streamWriter.WriteLine("***********************************************************************");
|
|
|
|
streamWriter.WriteLine(DateTime.Now.ToString("HH:mm:ss"));
|
|
|
|
streamWriter.WriteLine("输出信息:错误信息");
|
|
|
|
if (message != null)
|
|
|
|
{
|
|
|
|
streamWriter.WriteLine("异常信息:\r\n" + message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
if (streamWriter != null)
|
|
|
|
{
|
|
|
|
streamWriter.Flush();
|
|
|
|
if (streamWriter != null) {
|
|
|
|
streamWriter.Dispose();
|
|
|
|
streamWriter = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
streamWriter = !File.Exists(directPath) ? File.CreateText(directPath) : File.AppendText(directPath);
|
|
|
|
}
|
|
|
|
streamWriter.WriteLine("***********************************************************************");
|
|
|
|
streamWriter.WriteLine(DateTime.Now.ToString("HH:mm:ss"));
|
|
|
|
streamWriter.WriteLine("输出信息:信息");
|
|
|
|
if (message != null)
|
|
|
|
{
|
|
|
|
streamWriter.WriteLine("信息:\r\n" + message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
if (streamWriter != null)
|
|
|
|
{
|
|
|
|
streamWriter.Flush();
|
|
|
|
if (streamWriter != null)
|
|
|
|
{
|
|
|
|
streamWriter.Dispose();
|
|
|
|
streamWriter = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|