public static void InsertLog(string logFolder = "", string folder = "", string data = "")
{
FileStream fs = null;
try
{
string sPhysicPath = Environment.CurrentDirectory + $"/ErrorLogs/{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}/{logFolder}";
string strDirectory = string.Concat(sPhysicPath, "/", folder, "/", DateTime.Now.ToString("yyyyMM"));
string strFile = DateTime.Now.ToString("yyyy-MM-dd");
if (!Directory.Exists(strDirectory))
Directory.CreateDirectory(strDirectory);
fs = new FileStream(string.Concat(strDirectory, "/", strFile, ".txt"), FileMode.Append, FileAccess.Write);
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
sw.Write(("---------------------------------------------------------------\r\n" + DateTime.Now + ("\r\n" + (data + "\r\n" + "\r\n"))));
}
}
catch (Exception ex)
{
Log.WriteLogError(ex.ToString());
}
finally
{
if (fs != null)
{
fs.Dispose();
}
}
}
0 Nhận xét