.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Exception handling using NLog tool

Posted By: Kiran     Posted Date: July 12, 2014    Points:5   Category :ASP.Net
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
Author: ASPEvil             
Posted Date: July 16, 2014     Points: 20   
Author: Ashutosh Jha             
Posted Date: July 27, 2014     Points: 20   

Hey Kiran,

Please check below for exception handling-

http://nlog-project.org/2010/09/05/new-exception-handling-rules-in-nlog-2-0.html

Regards,
Ashutosh Jha
ashutosh741@gmail.com

http://www.tricksroad.com


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend