private static void InsertNormal(string Message, LogLevel Level, string ID_Correlation) { try { var log = new LogsInfo(); log.IDCorrelation = ID_Correlation; log.Message = Message; log.CodeLocation = GetCurrentStackTrace(); log.ApplicationIdentity = string.Format("{0}.{1}.{2}", Settings.ApplicationIdentity , Process.GetCurrentProcess().ProcessName, System.Environment.MachineName); log.Level = (byte)Level; Insert(log); } catch (Exception exx) { //InsertErrorToFile(exx, Level, ID_Correlation); //InsertNormalToFile(Message, Level, ID_Correlation); } }
private static void Insert(LogsInfo entity) { using (var connection = new SqlConnection(connectionString)) { connection.Open(); using (var command = new SqlCommand(KSP_INSERT, connection)) { object[] parameters = { //new SqlParameter("object_name", SqlHelper.GetDataValue(entity.object_name)), new SqlParameter("@IDCorrelation", GetDataValue(entity.IDCorrelation)) , new SqlParameter("@Message", GetDataValue(Left(entity.Message))) , new SqlParameter("@CodeLocation", GetDataValue(Left(entity.CodeLocation))) , new SqlParameter("@ApplicationIdentity", GetDataValue(Left(entity.ApplicationIdentity))) , new SqlParameter("@Level", GetDataValue(entity.Level)) , new SqlParameter("@StackTrace", GetDataValue(Left(entity.StackTrace))) , new SqlParameter("@Source", GetDataValue(Left(entity.Source))) }; command.Parameters.AddRange(parameters); command.ExecuteNonQuery(); } } }
private static void InsertError(Exception ex, LogLevel Level, string ID_Correlation) { try { var log = new LogsInfo(); log.IDCorrelation = ID_Correlation; log.CreatedDate = DateTime.Now; log.Message = ex.Message; log.CodeLocation = GetCurrentStackTrace(); log.ApplicationIdentity = string.Format("{0}.{1}.{2}", Settings.ApplicationIdentity, Process.GetCurrentProcess().ProcessName, System.Environment.MachineName); log.Level = (byte)Level; log.StackTrace = ex.StackTrace; log.Source = ex.Source; Insert(log); } catch (Exception exx) { Console.WriteLine(exx); //InsertErrorToFile(exx, Level, ID_Correlation); //InsertErrorToFile(ex, Level, ID_Correlation); } }