コード例 #1
0
ファイル: MySqlErrorLog.cs プロジェクト: psuvorov/ElmahCore
        public override int GetErrors(int errorIndex, int pageSize, ICollection <ErrorLogEntry> errorEntryList)
        {
            if (errorIndex < 0)
            {
                throw new ArgumentOutOfRangeException("errorIndex", errorIndex, null);
            }
            if (pageSize < 0)
            {
                throw new ArgumentOutOfRangeException("pageSize", pageSize, null);
            }

            using (var connection = new MySqlConnection(ConnectionString))
            {
                connection.Open();

                using (var command = CommandExtension.GetErrorsXml(ApplicationName, errorIndex, pageSize))
                {
                    command.Connection = connection;

                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var id    = reader.GetGuid(0);
                            var xml   = reader.GetString(1);
                            var error = ErrorXml.DecodeString(xml);
                            errorEntryList.Add(new ErrorLogEntry(this, id.ToString(), error));
                        }
                    }
                }

                return(this.GetTotalErrorsXml(connection));
            }
        }
コード例 #2
0
ファイル: MySqlErrorLog.cs プロジェクト: psuvorov/ElmahCore
 private int GetTotalErrorsXml(MySqlConnection connection)
 {
     using (var command = CommandExtension.GetTotalErrorsXml(ApplicationName))
     {
         command.Connection = connection;
         return(Convert.ToInt32(command.ExecuteScalar()));
     }
 }
コード例 #3
0
ファイル: MySqlErrorLog.cs プロジェクト: wickyhu/ElmahCore
        public override void Log(Guid id, Error error)
        {
            if (error == null)
            {
                throw new ArgumentNullException("error");
            }

            var errorXml = ErrorXml.EncodeString(error);

            using (var connection = new MySqlConnection(ConnectionString))
                using (var command = CommandExtension.LogError(id, ApplicationName, error.HostName, error.Type,
                                                               error.Source, error.Message, error.User, error.StatusCode, error.Time, errorXml))
                {
                    connection.Open();
                    command.Connection = connection;
                    command.ExecuteNonQuery();
                }
        }
コード例 #4
0
ファイル: MySqlErrorLog.cs プロジェクト: psuvorov/ElmahCore
        public override ErrorLogEntry GetError(string id)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (id.Length == 0)
            {
                throw new ArgumentException(null, "id");
            }

            Guid errorGuid;

            try
            {
                errorGuid = new Guid(id);
            }
            catch (FormatException e)
            {
                throw new ArgumentException(e.Message, "id", e);
            }

            string errorXml;

            using (var connection = new MySqlConnection(ConnectionString))
                using (var command = CommandExtension.GetErrorXml(ApplicationName, errorGuid))
                {
                    command.Connection = connection;
                    connection.Open();
                    errorXml = (string)command.ExecuteScalar();
                }

            if (errorXml == null)
            {
                return(null);
            }

            var error = ErrorXml.DecodeString(errorXml);

            return(new ErrorLogEntry(this, id, error));
        }
コード例 #5
0
ファイル: MySqlErrorLog.cs プロジェクト: psuvorov/ElmahCore
        /// <summary>
        /// Creates the neccessary tables used by this implementation
        /// </summary>
        private void CreateTableIfNotExist()
        {
            using (var connection = new MySqlConnection(this.ConnectionString))
            {
                connection.Open();
                var databaseName = connection.Database;

                using (var commandCheck = CommandExtension.CheckTable(databaseName))
                {
                    commandCheck.Connection = connection;
                    var exists = ((long)commandCheck.ExecuteScalar()) == 1;

                    if (!exists)
                    {
                        using (var commandCreate = CommandExtension.CreateTable())
                        {
                            commandCreate.Connection = connection;
                            commandCreate.ExecuteNonQuery();
                        }
                    }
                }
            }
        }