Class inheriting ILog for writing logs to a text file
Inheritance: ILog, IDisposable
Example #1
0
        /// <summary>
        /// Sets the database connection and the initial log level.
        /// </summary>
        /// <param name="db">Database connection</param>
        /// <param name="textlogFilepath">File path to a backup text log in case the SQL log fails</param>
        /// <param name="clearTextLog"></param>
        public SqlLog(IDbConnection db, string textlogFilepath, bool clearTextLog)
        {
            FileName = string.Format("{0}://database", db.GetSqlType());
            _database = db;
            _backupLog = new TextLog(textlogFilepath, clearTextLog);

            var table = new SqlTable("Logs",
                new SqlColumn("ID", MySqlDbType.Int32) {AutoIncrement = true, Primary = true},
                new SqlColumn("TimeStamp", MySqlDbType.Text),
                new SqlColumn("LogLevel", MySqlDbType.Int32),
                new SqlColumn("Caller", MySqlDbType.Text),
                new SqlColumn("Message", MySqlDbType.Text)
                );

            var creator = new SqlTableCreator(db,
                db.GetSqlType() == SqlType.Sqlite
                    ? (IQueryBuilder) new SqliteQueryCreator()
                    : new MysqlQueryCreator());
            creator.EnsureTableStructure(table);
        }
Example #2
0
        /// <summary>
        /// Sets the database connection and the initial log level.
        /// </summary>
        /// <param name="db">Database connection</param>
        /// <param name="textlogFilepath">File path to a backup text log in case the SQL log fails</param>
        /// <param name="clearTextLog"></param>
        public SqlLog(IDbConnection db, string textlogFilepath, bool clearTextLog)
        {
            FileName   = string.Format("{0}://database", db.GetSqlType());
            _database  = db;
            _backupLog = new TextLog(textlogFilepath, clearTextLog);

            var table = new SqlTable("Logs",
                                     new SqlColumn("ID", MySqlDbType.Int32)
            {
                AutoIncrement = true, Primary = true
            },
                                     new SqlColumn("TimeStamp", MySqlDbType.Text),
                                     new SqlColumn("LogLevel", MySqlDbType.Int32),
                                     new SqlColumn("Caller", MySqlDbType.Text),
                                     new SqlColumn("Message", MySqlDbType.Text)
                                     );

            var creator = new SqlTableCreator(db,
                                              db.GetSqlType() == SqlType.Sqlite
                                        ? (IQueryBuilder) new SqliteQueryCreator()
                                        : new MysqlQueryCreator());

            creator.EnsureTableStructure(table);
        }