//File Write
public static void File(string Message)
{
StreamWriter sw = null;
try
{
string sLogFormat = DateTime.Now.ToShortDateString().ToString() + " | " + DateTime.Now.ToLongTimeString().ToString() + " | " + Global.UserName + " | " + Environment.MachineName + " ==> ";
string sPathName = C:\ + "\\Log" + "\\";
string sYear = DateTime.Now.Year.ToString();
string sMonth = DateTime.Now.Month.ToString();
string sDay = DateTime.Now.Day.ToString();
string sErrorTime = sDay + "-" + sMonth + "-" + sYear;
sw = new StreamWriter(sPathName + "Test_" + sErrorTime + ".txt", true);
sw.WriteLine(sLogFormat + Message);
sw.Flush();
}
catch (Exception ex)
{
ErrorLog(ex.ToString());
}
finally
{
if (sw != null)
{
sw.Dispose();
sw.Close();
}
}
}
===============================================================
O/P:= 05/05/2016 | 10:46:49 | ADMIN | TEST | ==> HELLO.........
public static void File(string Message)
{
StreamWriter sw = null;
try
{
string sLogFormat = DateTime.Now.ToShortDateString().ToString() + " | " + DateTime.Now.ToLongTimeString().ToString() + " | " + Global.UserName + " | " + Environment.MachineName + " ==> ";
string sPathName = C:\ + "\\Log" + "\\";
string sYear = DateTime.Now.Year.ToString();
string sMonth = DateTime.Now.Month.ToString();
string sDay = DateTime.Now.Day.ToString();
string sErrorTime = sDay + "-" + sMonth + "-" + sYear;
sw = new StreamWriter(sPathName + "Test_" + sErrorTime + ".txt", true);
sw.WriteLine(sLogFormat + Message);
sw.Flush();
}
catch (Exception ex)
{
ErrorLog(ex.ToString());
}
finally
{
if (sw != null)
{
sw.Dispose();
sw.Close();
}
}
}
===============================================================
O/P:= 05/05/2016 | 10:46:49 | ADMIN | TEST | ==> HELLO.........
No comments:
Post a Comment