using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace ButcherFactory.Utils
{
  public static class LogUtil
  {
    /// <summary>
    /// 记录失败日志
    /// </summary>
    /// <param name="content">内容</param>
    /// <param name="type">类型（oa mdg sap）</param>
    public static void WriteErrorFile(string content, string flag)
    {
      var fileName = string.Format("Log/{0}{1:yyyy-MM-dd}.txt", flag, DateTime.Today);

      WriteLog(fileName, content);
    }

    static object _lock = new object();
    /// <summary>
    /// 记录日志
    /// </summary>
    /// <param name="fieldName">文件名称</param>
    /// <param name="content">内容</param>
    static void WriteLog(string fieldName, string content)
    {
      lock (_lock)
      {
        try
        {
          using (StreamWriter file = new StreamWriter(fieldName, true, Encoding.UTF8))
          {
            file.WriteLine(content);// 直接追加文件末尾，换行  
          }
        }
        catch
        {
        }
      }
    }
  }
}
