Hello,
I have unhandled exception logger which logs every error into a table. Actually, it works but there is a rare condition when I do a load test with more than 1000 users, errors aren't written into this table. (950 success, 50 errors) Why could this happen? Any ideas? 50 users didn't even start for some reason?
I have unhandled exception logger which logs every error into a table. Actually, it works but there is a rare condition when I do a load test with more than 1000 users, errors aren't written into this table. (950 success, 50 errors) Why could this happen? Any ideas? 50 users didn't even start for some reason?
C#:
public class UnhandledExceptionLogger : ExceptionLogger
{
public override void Log(ExceptionLoggerContext context)
{
var ex = context.Exception;
string strLogText = "";
strLogText += Environment.NewLine + "Source ---\n{0}" + ex.Source;
strLogText += Environment.NewLine + "StackTrace ---\n{0}" + ex.StackTrace;
strLogText += Environment.NewLine + "TargetSite ---\n{0}" + ex.TargetSite;
if (ex.InnerException != null)
{
strLogText += Environment.NewLine + "Inner Exception is {0}" + ex.InnerException;//error prone
}
if (ex.Message != null)
{
strLogText += Environment.NewLine + "Message ---\n{0}" + ex.Message;//error prone
}
var requestedURi = (string)context.Request.RequestUri.AbsoluteUri;
var requestMethod = context.Request.Method.ToString();
var timeUtc = DateTime.Now;
SqlErrorLogging sqlErrorLogging = new SqlErrorLogging();
ApiError apiError = new ApiError()
{
Message = strLogText,
RequestUri = requestedURi,
RequestMethod = requestMethod,
TimeUtc = DateTime.Now
};
sqlErrorLogging.InsertErrorLog(apiError);
}
}
C#:
public void InsertErrorLog(ApiError apiError)
{
using (var sqlConnection =
new SqlConnection(ConfigurationManager.ConnectionStrings["GameContext"].ConnectionString))
{
try
{
sqlConnection.Open();
using (SqlCommand cmd =
new SqlCommand(
"INSERT INTO [dbo].[API_Error] ([Message],[RequestMethod],[RequestUri],[TimeUtc]) VALUES (@Message, @RequestMethod, @RequestUri, @TimeUtc)",
sqlConnection))
{
cmd.Parameters.AddWithValue("@TimeUtc", apiError.TimeUtc);
cmd.Parameters.AddWithValue("@RequestUri", apiError.RequestUri);
cmd.Parameters.AddWithValue("@Message", apiError.Message);
cmd.Parameters.AddWithValue("@RequestMethod", apiError.RequestMethod);
cmd.ExecuteNonQuery();
}
}
catch (Exception e)
{
throw e;
}
finally
{
sqlConnection.Close();
}
}
}