You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.5 KiB
51 lines
1.5 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace PunchingMistake
|
|
{
|
|
public class LogHelper
|
|
{
|
|
private static string CodeVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString().Trim();
|
|
|
|
//<summary>
|
|
//保存日志的文件夹
|
|
//<summary>
|
|
private static string logPath = AppDomain.CurrentDomain.BaseDirectory + @"log\";
|
|
/// <summary>
|
|
/// 写日志
|
|
/// </summary>
|
|
/// <param name="msg"></param>
|
|
/// <param name="errorFile"></param>
|
|
public static void WriteLog(string msg, string errorFile = "")
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(msg))
|
|
{
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
msg = string.Format("程序版本号:{0},Time:{1},Message:{2}", CodeVersion, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff"), msg);
|
|
}
|
|
//如果不存在log文件夹 则创建
|
|
if (!Directory.Exists(logPath))
|
|
{
|
|
Directory.CreateDirectory(logPath);
|
|
}
|
|
|
|
StreamWriter sw = File.AppendText(logPath + errorFile + DateTime.Now.ToString("yyyyMMdd") + ".Log");
|
|
sw.WriteLine(msg);
|
|
sw.Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|