how to create error log file in asp.net

Posted by Gow.Net under ASP.NET on 7/22/2012 | Points: 10 | Views : 3278 | Status : [Member] | Replies : 5
how to create error log file in asp.net what are the different types of method available in log file file creation any one help me

gowthaman8870226416


Responses

Posted by: Ranjeet_8 on: 7/23/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Write this code in Global.asax Page
it will help u...

  void Application_Error(object sender, EventArgs e)

{
Try
{
// Code that runs when an unhandled error occurs

// Get the error details
HttpContext CurrentHTTPcontext = HttpContext.Current;
HttpException lastErrorWrapper = Server.GetLastError() as HttpException;

Exception lastError = lastErrorWrapper;
if (lastErrorWrapper.InnerException != null)
lastError = lastErrorWrapper.InnerException;

string ErrorPageURL = CurrentHTTPcontext.Request.Url.ToString();
string ErrorMessage = lastError.Message;
string ErrorStackTrace = lastError.StackTrace;

MainFunction mainfun = new MainFunction();
SqlConnection sqlcon = new SqlConnection(ConfigurationSettings.AppSettings["CON"]);
Try
{

SqlCommand sqlcmd = new SqlCommand();
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Connection = sqlcon;

sqlcmd.Parameters.Add(new SqlParameter("@PageURL", SqlDbType.VarChar, 500)).Value = Server.HtmlEncode(ErrorPageURL);
sqlcmd.Parameters.Add(new SqlParameter("@ErrorMessage", SqlDbType.VarChar, 2000)).Value = Server.HtmlEncode(ErrorMessage);
sqlcmd.Parameters.Add(new SqlParameter("@ErrorStackTrace", SqlDbType.Text)).Value = Server.HtmlEncode(ErrorStackTrace);
sqlcmd.CommandText = "Sp__ErrorLog"; // Procedure Name

if (sqlcon.State == ConnectionState.Closed)
{
sqlcon.Open();
}

sqlcmd.ExecuteNonQuery();

if (sqlcon.State == ConnectionState.Open)
{
sqlcon.Close();
}
}
catch
{
if (sqlcon.State == ConnectionState.Open)
{
sqlcon.Close();
}
}


}
catch
{

}

}


Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 7/23/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Hi..
look at this url
http://www.dotnetfunda.com/codes/code2838-how-to-get-error-log-in-aspnet.aspx

.

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Patel28rajendra on: 7/24/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

refer this link
http://www.codeproject.com/Articles/2344/Create-Simple-Error-Log-Files-using-ASP-NET-and-C

R D Patel

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Patel28rajendra on: 7/24/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

another one

http://www.dotnetcurry.com/ShowArticle.aspx?ID=94

R D Patel

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Patel28rajendra on: 7/24/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

here is nice article
http://www.dotnetfunda.com/articles/article1070-error-logging-in-aspnet.aspx

R D Patel

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response