// Method
private static String ErrorlineNo, Errormsg, extype, exurl,
hostIp, ErrorLocation, HostAdd;
public static void Write_Logs(Exception
ex)
{
var line = Environment.NewLine
+ Environment.NewLine;
ErrorlineNo = ex.StackTrace.Substring(ex.StackTrace.Length - 7, 7);
Errormsg = ex.GetType().Name.ToString();
extype = ex.GetType().ToString();
exurl
= context.Current.Request.Url.ToString();
ErrorLocation = ex.Message.ToString();
try
{
string filepath = context.Current.Server.MapPath("~/Ex_Log/"); //Text File Path
if (!Directory.Exists(filepath))
{
Directory.CreateDirectory(filepath);
}
filepath = filepath + DateTime.Today.ToString("dd-MM-yy") + ".txt"; //Text File Name
if (!File.Exists(filepath))
{
File.Create(filepath).Dispose();
}
using (StreamWriter
sw = File.AppendText(filepath))
{
sw.WriteLine(line);
string error = "Date:"
+ " " + DateTime.Now.ToString()
+ "," + "LineNo
:" + " " + ErrorlineNo
+ "," + "Message:"
+ " " + Errormsg + "," + "ExceptionType:"
+ " " + extype + "," + "Location
:" + " " +
ErrorLocation + "," + "PageUrl:" + "
" + exurl + "," + "HostIP:" + "
" + hostIp;
sw.Flush();
sw.Close();
}
}
catch (Exception
e)
{
e.ToString();
}
}
//Call
protected void btn_backCatalogue_Click(object
sender, EventArgs e)
{
try
{
}
catch (Exception
ex)
{
Write_Logs(ex);
}
}
No comments:
Post a Comment