150 lines
5.4 KiB
C#
150 lines
5.4 KiB
C#
using System;
|
||||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Windows.Forms;
|
|||
|
|
using System.IO;
|
|||
|
|
|
|||
|
|
namespace HxBusiness
|
|||
|
|
{
|
|||
|
|
public class WriteTxt
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
private static object obj_saveLog1 = new object();
|
|||
|
|
/// <summary>
|
|||
|
|
/// AGV读取的地标值记录
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="fileMsg">日志文件路径</param>
|
|||
|
|
/// <param name="filename">文件名称</param>
|
|||
|
|
/// <param name="Assembly_name">线体名称</param>
|
|||
|
|
public static void SaveLog1(string fileMsg, string filename="插件日志", string Assembly_name ="插件日志" )
|
|||
|
|
{
|
|||
|
|
lock (obj_saveLog1)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
using (FileStream _fStream = new FileStream(GetFilePath1(filename, Assembly_name) , FileMode.Append, FileAccess.Write))
|
|||
|
|
{
|
|||
|
|
using (StreamWriter _sWrite = new StreamWriter(_fStream))
|
|||
|
|
{
|
|||
|
|
_sWrite.WriteLine(GetCurrentTimeString() + fileMsg);
|
|||
|
|
_sWrite.Close();
|
|||
|
|
_fStream.Close();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception)
|
|||
|
|
{
|
|||
|
|
SaveLog1(fileMsg, filename, Assembly_name);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private static object obj_saveLog4 = new object();
|
|||
|
|
/// <summary>
|
|||
|
|
/// AGV读取的地标值记录
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="fileMsg">日志文件路径</param>
|
|||
|
|
/// <param name="filename">文件名称</param>
|
|||
|
|
/// <param name="Assembly_name">线体名称</param>
|
|||
|
|
public static void SaveLog4(string fileMsg, string filename, string Assembly_name)
|
|||
|
|
{
|
|||
|
|
lock (obj_saveLog4)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
using (FileStream _fStream = new FileStream(GetFilePath1(filename, Assembly_name), FileMode.Append, FileAccess.Write))
|
|||
|
|
{
|
|||
|
|
using (StreamWriter _sWrite = new StreamWriter(_fStream))
|
|||
|
|
{
|
|||
|
|
_sWrite.WriteLine(GetCurrentTimeString() + fileMsg);
|
|||
|
|
_sWrite.Close();
|
|||
|
|
_fStream.Close();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception)
|
|||
|
|
{
|
|||
|
|
SaveLog1(fileMsg, filename, Assembly_name);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private static string GetCurrentTimeString()
|
|||
|
|
{
|
|||
|
|
return "[" + DateTime.Now.ToLongTimeString() + "]:";//+ "." + DateTime.Now.Millisecond.ToString("000")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private static string GetFilePath1(string str, string Assembly_Name)
|
|||
|
|
{
|
|||
|
|
string path = Application.StartupPath + @"\log\" + DateTime.Now.ToString("yyyyMMdd")+@"\"+ Assembly_Name;
|
|||
|
|
if (!Directory.Exists(path))
|
|||
|
|
{
|
|||
|
|
Directory.CreateDirectory(path);
|
|||
|
|
}
|
|||
|
|
string pa = Application.StartupPath + @"\log\" + DateTime.Now.ToString("yyyyMMdd") + @"\" + Assembly_Name;
|
|||
|
|
if (!Directory.Exists(pa))
|
|||
|
|
{
|
|||
|
|
Directory.CreateDirectory(pa);
|
|||
|
|
}
|
|||
|
|
return pa + @"\" + str + "_.log";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private static object obj_saveLog2 = new object();
|
|||
|
|
public static void SaveLog2(string fileMsg)
|
|||
|
|
{
|
|||
|
|
lock (obj_saveLog2)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
if (!Directory.Exists(@"c:\pathlog\"))
|
|||
|
|
{
|
|||
|
|
Directory.CreateDirectory(@"c:\pathlog\");
|
|||
|
|
}
|
|||
|
|
using (FileStream _fStream = new FileStream(@"c:\pathlog\" + DateTime.Now.ToString("yyyyMMdd") + "_.log", FileMode.Append, FileAccess.Write))
|
|||
|
|
{
|
|||
|
|
using (StreamWriter _sWrite = new StreamWriter(_fStream))
|
|||
|
|
{
|
|||
|
|
_sWrite.WriteLine(GetCurrentTimeString() + fileMsg);
|
|||
|
|
_sWrite.Close();
|
|||
|
|
_fStream.Close();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception)
|
|||
|
|
{
|
|||
|
|
SaveLog2(fileMsg);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private static object obj_saveLog3 = new object();
|
|||
|
|
public static void SaveLog3(string fileMsg,string id)
|
|||
|
|
{
|
|||
|
|
lock (obj_saveLog3)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
if (!Directory.Exists(@"c:\neclog\" + DateTime.Now.ToString("yyyyMMdd")))
|
|||
|
|
{
|
|||
|
|
Directory.CreateDirectory(@"c:\neclog\" + DateTime.Now.ToString("yyyyMMdd"));
|
|||
|
|
}
|
|||
|
|
using (FileStream _fStream = new FileStream(@"c:\neclog\" + DateTime.Now.ToString("yyyyMMdd") +@"\"+id+ "_.log", FileMode.Append, FileAccess.Write))
|
|||
|
|
{
|
|||
|
|
using (StreamWriter _sWrite = new StreamWriter(_fStream))
|
|||
|
|
{
|
|||
|
|
_sWrite.WriteLine(GetCurrentTimeString() + fileMsg);
|
|||
|
|
_sWrite.Close();
|
|||
|
|
_fStream.Close();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception)
|
|||
|
|
{
|
|||
|
|
SaveLog3(fileMsg,id);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|