Exception handling using NLog Tool

Posted by Vedashree under ASP.NET on 7/12/2014 | Points: 10 | Views : 1278 | Status : [Member] | Replies : 0
Hi Everyone,

I am using below static method to log the exceptions into DataBase in my ASP.net application.
But now i want to have the logging by using NLog tool. Can anyone guide me through this one. I am not getting any way to solve it and stuck up completely.

 public static class EventLogger
{
const string insertException = "dbo.InsertExceptionsLog";
string connString = "";

public void InsertException(string source, string systemName, string exceptionDetails, DateTime timeGenerated, string userName)
{
using (SqlConnection conn = new SqlConnection(connString))
{
try
{
conn.Open();
using (SqlTransaction tran = conn.BeginTransaction())
{
try
{

SqlParameter[] parms = new SqlParameter[6];

parms[0] = new SqlParameter("@Source", SqlDbType.VarChar);
parms[0].Value = source;

parms[1] = new SqlParameter("@SystemName", SqlDbType.VarChar);
parms[1].Value = systemName;

parms[2] = new SqlParameter("@ExceptionDetails", SqlDbType.Text);
parms[2].Value = exceptionDetails;

parms[3] = new SqlParameter("@TimeGenerated", SqlDbType.DateTime);
parms[3].Value = timeGenerated;

parms[4] = new SqlParameter("@TimeWritten", SqlDbType.DateTime);
parms[4].Value = DateTime.Now; // timeWritten;

parms[5] = new SqlParameter("@UserName", SqlDbType.VarChar);
parms[5].Value = userName;

SqlHelper.ExecuteNonQuery(tran, CommandType.StoredProcedure, "InsertExceptionsLog", parms);
tran.Commit();
}

catch (Exception ex)
{
tran.Rollback();
throw (ex);
}
}

}
catch (Exception ex)
{
throw (ex);
}

}

}

}



My database table is
SELECT [ExceptionID]
,[Source]
,[SystemName]
,[ExceptionDetails]
,[TimeGenerated]
,[TimeWritten]
,[UserName]
FROM [CPS_CL_Application_Exception].[dbo].[ExceptionDetails]
order by [ExceptionID] desc


My stored Procedure is
SELECT [ExceptionID]
,[Source]
,[SystemName]
,[ExceptionDetails]
,[TimeGenerated]
,[TimeWritten]
,[UserName]
FROM [CPS_CL_Application_Exception].[dbo].[ExceptionDetails]
order by [ExceptionID] desc





Responses

(No response found.)

Login to post response