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();
}
///
/// 通过设备
///
///
///
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();
}
}
}