May 23, 2014

Save You Errors In A Notepad C#

You Could Write It Any Where You Want .
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.

No comments:

JWT Token Decode Using Jquery

When it come to authentication we use many mechanism. Ones the user authenticated we must keep these details somewhere safe. So we can share...