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.
113 lines
3.2 KiB
113 lines
3.2 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.IO;
|
|
using System.Configuration;
|
|
|
|
namespace OpcService
|
|
{
|
|
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();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过设备
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
/// <param name="machineName"></param>
|
|
public static void Error(string info, string machineName)
|
|
{
|
|
string filePath = ConfigurationManager.AppSettings["logFilePath"];
|
|
|
|
if (string.IsNullOrEmpty(filePath))
|
|
{
|
|
filePath = System.AppDomain.CurrentDomain.BaseDirectory + @"\Error";
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
}
|
|
}
|
|
|