示例#1
0
        internal static void WriteExceptionToDatabase(
            String exception,
            String innerException,
            String stackTrace,
            String exceptionMethod,
            String exceptionClass,
            DateTime dateTime,
            LogType type,
            String extraInformation)
        {
            String _type = LogTypeUtils.GetType(type);

            try
            {
                using (var connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    var query = @"INSERT INTO LMK.LOG_HISTORY VALUES (
                                 @exception, 
                                 @innerException, 
                                 @stackTrace,
                                 @exceptionMethod, 
                                 @exceptionClass, 
                                 @exceptionDate, 
                                 @exceptionTime, 
                                 @exceptionType, 
                                 @extraInformation
                            )";
                    using (var command = new SqlCommand(query, connection))
                    {
                        command.Parameters.Add("@exception", SqlDbType.NVarChar, -1).Value          = exception;
                        command.Parameters.Add("@innerException", SqlDbType.NVarChar, -1).Value     = innerException;
                        command.Parameters.Add("@stackTrace", SqlDbType.NVarChar, -1).Value         = stackTrace;
                        command.Parameters.Add("@exceptionMethod", SqlDbType.NVarChar, 100).Value   = exceptionMethod;
                        command.Parameters.Add("@exceptionClass", SqlDbType.NVarChar, 100).Value    = exceptionClass;
                        command.Parameters.Add("@exceptionDate", SqlDbType.Date).Value              = dateTime.Date;
                        command.Parameters.Add("@exceptionTime", SqlDbType.Time).Value              = dateTime.TimeOfDay;
                        command.Parameters.Add("@exceptionType", SqlDbType.NVarChar, 30).Value      = _type;
                        command.Parameters.Add("@extraInformation", SqlDbType.NVarChar, 3000).Value = extraInformation;
                        command.ExecuteNonQuery();
                        connection.Close();
                    }
                }
            }
            catch (SqlException)
            {
                throw;
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#2
0
        public static void WriteExceptionToFile(
            String exception,
            String innerException,
            String stackTrace,
            String exceptionMethod,
            String exceptionClass,
            DateTime dateTime,
            LogType type,
            String extraInformation)
        {
            var fileName = filePath + "/" + DateTime.Now.Date.ToShortDateString().Replace('/', '_') + ".csv";
            var contents = exception.Replace('\n', ' ').Replace('\r', ' ').Replace(',', ' ')
                           + "," + innerException.Replace('\n', ' ').Replace('\r', ' ').Replace(',', ' ')
                           + "," + stackTrace.Replace('\n', ' ').Replace('\r', ' ').Replace(',', ' ')
                           + "," + exceptionMethod + "," + exceptionClass + ","
                           + dateTime.ToString() + ","
                           + LogTypeUtils.GetType(type)
                           + "," + extraInformation + "\n";

            try
            {
                if (File.Exists(fileName))
                {
                    File.AppendAllText(fileName, contents);
                }
                else
                {
                    File.AppendAllText(fileName, "Exception,Inner Exception,Stack Trace,Exception Method,Exception Class, Date Time,Type,Extra Information\n");
                    File.AppendAllText(fileName, contents);
                }
            }
            catch
            {
                throw;
            }
        }