天津投入产出系统后端
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.

78 lines
2.1 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Configuration;
namespace EQUIPINTERFACETEST
{
public static class WriteLog
{
public static void Write(string info)
{
string filePath = ConfigurationManager.AppSettings["logFilePath"];
if (string.IsNullOrEmpty(filePath))
{
filePath = System.AppDomain.CurrentDomain.BaseDirectory + @"\LogFile";
}
if (Directory.Exists(filePath) == false)
{
Directory.CreateDirectory(filePath);
}
if (File.Exists(filePath + @"\logtxt.txt") == false)
{
File.Create(filePath + @"\logtxt.txt").Close();
}
StreamWriter sw = File.AppendText(filePath + @"\logtxt.txt");
sw.WriteLine(info);
sw.Flush();
sw.Close();
}
/// <summary>
/// 通过设备
/// </summary>
/// <param name="info"></param>
/// <param name="machineName"></param>
public static void Write(string info, string machineName)
{
string filePath = ConfigurationManager.AppSettings["logFilePath"];
if (string.IsNullOrEmpty(filePath))
{
filePath = System.AppDomain.CurrentDomain.BaseDirectory + @"\LogFile";
}
filePath += @"\" + machineName;
if (Directory.Exists(filePath) == false)
{
Directory.CreateDirectory(filePath);
}
if (File.Exists(filePath + string.Format(@"\{0}.txt", System.DateTime.Now.ToString("yyyyMMdd"))) == false)
{
File.Create(filePath + string.Format(@"\{0}.txt", System.DateTime.Now.ToString("yyyyMMdd"))).Close();
}
StreamWriter sw = File.AppendText(filePath + string.Format(@"\{0}.txt", System.DateTime.Now.ToString("yyyyMMdd")));
sw.WriteLine(info);
sw.Flush();
sw.Close();
}
}
}