You Could Write It Inside Every Function If You Need To.
I Have Used It Under A Button Click
protected void Button1_Click(object sender, EventArgs e)
{
TestClass t = new TestClass();
DateTime time = DateTime.Now;
try
{
throw new Exception("Sql Error");
}
catch (Exception error)
{
TextBox1.Text = "" + error.Message;
t.errorLogger(time.ToString(), "Your Function Name", ""+error.Message);
}
}
I Have Created A Class Name TestClass and created a object above and
called the function inside the class.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Error_Handling
{
public class TestClass
{
public void errorLogger(string time,string functionName,string errorOccured)
{
string lines = "Time : " + time + " | Function Name : " + functionName + " | Error Occured : " + errorOccured;
System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\test.txt", true);
file.WriteLine(lines);
file.Close();
}
}
}
You will have to specify the path of the notepad above.