Exemplo n.º 1
0
            public static void CreateLogDb(FileInfo file)
            {
                using (var conn = new SQLiteConnection())
                {
                    conn.ConnectionString = SqlLiteDataAccess.LoadConnectionString();
                    conn.Open();
                    var cmd = conn.CreateCommand();

                    cmd.CommandText =
                        @"CREATE TABLE BoardsLog(
                            LogId     INTEGER PRIMARY KEY,
                            Date      DATETIME NOT NULL,
                            Level     VARCHAR(50) NOT NULL,
                            Logger    VARCHAR(255) NOT NULL,
                            Message   VARCHAR(255) DEFAULT NULL
                        );";
                    // / try
                    // {
                    cmd.ExecuteNonQuery();
                    // }
                    //catch (Exception)
                    //{
                    //}

                    cmd.Dispose();
                    conn.Close();
                }
            }
Exemplo n.º 2
0
            public static IAppender GetSqliteAppender(string dbFilename)
            {
                var dbFile = new FileInfo(dbFilename);

                if (!dbFile.Exists)
                {
                    CreateLogDb(dbFile);
                }

                var appender = new AdoNetAppender
                {
                    BufferSize       = 1,
                    ConnectionType   = "System.Data.SQLite.SQLiteConnection, System.Data.SQLite",
                    ConnectionString = SqlLiteDataAccess.LoadConnectionString(),
                    CommandText      = "INSERT INTO Board (Date, Level, Logger, Message) VALUES (@Date, @Level, @Logger, @Message)"
                };

                //appender.AddParameter(new AdoNetAppenderParameter
                //{
                //    ParameterName = "@SerialNumber",
                //    DbType = DbType.String,
                //    Layout = new Layout2RawLayoutAdapter(new PatternLayout("%serialnumber"))

                //});

                appender.AddParameter(new AdoNetAppenderParameter
                {
                    ParameterName = "@Date",
                    DbType        = DbType.DateTime,
                    Layout        = new RawTimeStampLayout()
                });

                appender.AddParameter(new AdoNetAppenderParameter
                {
                    ParameterName = "@Level",
                    DbType        = DbType.String,
                    Layout        = new Layout2RawLayoutAdapter(new PatternLayout("%level"))
                });

                appender.AddParameter(new AdoNetAppenderParameter
                {
                    ParameterName = "@Logger",
                    DbType        = DbType.String,
                    Layout        = new Layout2RawLayoutAdapter(new PatternLayout("%logger"))
                });

                appender.AddParameter(new AdoNetAppenderParameter
                {
                    ParameterName = "@Message",
                    DbType        = DbType.String,
                    Layout        = new Layout2RawLayoutAdapter(new PatternLayout("%message"))
                });

                appender.ActivateOptions();
                return(appender);
            }