82 lines
2.9 KiB
C#
82 lines
2.9 KiB
C#
using System.Text;
|
|
|
|
namespace Complex.Application.Common
|
|
{
|
|
public class FileIO
|
|
{
|
|
//==============================================================
|
|
|
|
public FileIO()
|
|
{
|
|
//
|
|
// TODO: Add constructor logic here
|
|
//
|
|
}
|
|
//==============================================================
|
|
|
|
/// <summary>
|
|
/// ثبت محتوا در یک فایل
|
|
/// </summary>
|
|
/// <param name="fileName">نام فایل</param>
|
|
/// <param name="content">محتوای فایل</param>
|
|
public static void Write(string fileName, string content, bool activeInServer = false)
|
|
{
|
|
//if (!SystemDefine.IsLocal && !activeInServer)
|
|
// return;
|
|
//System.IO.File.AppendAllText(HttpContext.Current.Server.MapPath("/FileIO/" + fileName), content, Encoding.UTF8);
|
|
Writeln(fileName, content, activeInServer);
|
|
}
|
|
//==============================================================
|
|
|
|
public static void Clear(string fileName)
|
|
{
|
|
//return;
|
|
System.IO.File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "/FileIO/" + fileName, "", Encoding.UTF8);
|
|
}
|
|
//==============================================================
|
|
|
|
/// <summary>
|
|
/// ثبت محتوا در یک فایل در یک خط جدید
|
|
/// </summary>
|
|
/// <param name="fileName">نام فایل</param>
|
|
/// <param name="content">محتوای فایل</param>
|
|
public static void Writeln(string fileName, string content, bool activeInServer = false)
|
|
{
|
|
|
|
//try
|
|
{
|
|
|
|
System.IO.File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + "/FileIO/" + fileName, content + "\r\n", Encoding.UTF8);
|
|
}
|
|
//catch { }
|
|
}
|
|
//==============================================================
|
|
|
|
/// <summary>
|
|
/// ثبت محتوا در یک فایل در یک خط جدید
|
|
/// </summary>
|
|
/// <param name="fileName">نام فایل</param>
|
|
/// <param name="content">محتوای فایل</param>
|
|
public static void Writeln(string fileName, string description, Exception exc, bool activeInServer = false)
|
|
{
|
|
//if (!SystemDefine.IsLocal && !activeInServer)
|
|
// return;
|
|
|
|
try
|
|
{
|
|
Writeln(fileName, ">>>>>>");
|
|
Writeln(fileName, description);
|
|
while (exc != null)
|
|
{
|
|
Writeln(fileName, exc.Message);
|
|
Writeln(fileName, exc.StackTrace);
|
|
exc = exc.InnerException;
|
|
}
|
|
Writeln(fileName, "<<<<<<");
|
|
}
|
|
catch { }
|
|
}
|
|
//==============================================================
|
|
}
|
|
}
|