You can use any of the below logging libraries as shown below described here.
Log4net (Logging in text file + logging in SQL database)
Nlog (Logging in text file + logging in SQL database)
Serilog (Logging in text file + logging in SQL database)
Elmah (logging in SQL database)
Alternatively you can create a procedure to track and insert the log/issue in the database manually as below.
try
{
//Your code here.
}
catch (Exception ex)
{
ExceptionLogging.SendExcepToDB(ex);
Label1.Text = "Some Technical Error occurred,Please visit after some time";
}
You can get the details from here.