Elmah.SQLiteErrorLog.Log C# (CSharp) Méthode

Log() public méthode

Logs an error to the database.
Use the stored procedure called by this implementation to set a policy on how long errors are kept in the log. The default implementation stores all errors for an indefinite time.
public Log ( Error error ) : string
error Error
Résultat string
        public override string Log(Error error)
        {
            if (error == null)
                throw new ArgumentNullException("error");

            string errorXml = ErrorXml.EncodeString(error);

            const string query = @"
                INSERT INTO Error (
                    Application, Host,
                    Type, Source, Message, User, StatusCode,
                    TimeUtc, AllXml)
                VALUES (
                    @Application, @Host,
                    @Type, @Source, @Message, @User, @StatusCode,
                    @TimeUtc, @AllXml);

                SELECT last_insert_rowid();";

            using (SQLiteConnection connection = new SQLiteConnection(ConnectionString))
            using (SQLiteCommand command = new SQLiteCommand(query, connection))
            {
                SQLiteParameterCollection parameters = command.Parameters;

                parameters.Add("@Application", DbType.String, 60).Value = ApplicationName;
                parameters.Add("@Host", DbType.String, 30).Value = error.HostName;
                parameters.Add("@Type", DbType.String, 100).Value = error.Type;
                parameters.Add("@Source", DbType.String, 60).Value = error.Source;
                parameters.Add("@Message", DbType.String, 500).Value = error.Message;
                parameters.Add("@User", DbType.String, 50).Value = error.User;
                parameters.Add("@StatusCode", DbType.Int64).Value = error.StatusCode;
                parameters.Add("@TimeUtc", DbType.DateTime).Value = error.Time.ToUniversalTime();
                parameters.Add("@AllXml", DbType.String).Value = errorXml;

                connection.Open();

                return Convert.ToInt64(command.ExecuteScalar()).ToString(CultureInfo.InvariantCulture);
            }
        }