Пример #1
0
        public void Store(string component, string shortMessage, string fullMessage, FDLogVerbosity importance)
        {
            if((int)importance >= (int)verbosity) return;

            DataStore.StoreLogMessage(importance, component, shortMessage, fullMessage, DateTime.Now);

            if(console) //we write the message to the console also
            {
                Console.WriteLine ("--- " + DateTime.Now.ToString() + ": " + component + "(" + importance + ") ---");
                Console.WriteLine (shortMessage);
            }
        }
Пример #2
0
        public FDDataStore(string DataStore, FDLogVerbosity logVerbosity)
        {
            DataStoreURI = DataStore;
            verbosity = logVerbosity;
            if(!File.Exists (DataStoreURI)) //if the file doesn't exist yet
            {
                if(!File.Exists(Path.GetDirectoryName(DataStoreURI))) //if the directory doesn't exist
                {
                    try
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName (DataStoreURI));
                    }
                    catch (Exception e)
                    {
                        throw new Exception("Couldn't create data store directory. " + e.Message);
                    }
                }

                try //create the file
                {
                    File.Create (DataStoreURI);
                }
                catch (Exception e)
                {
                    throw new Exception("Couldn't create the data store file. " + e.Message);
                }

            }

            //Now we'll connect
            string connectionString = "URI=file:" + DataStoreURI;
            dbcon = (IDbConnection) new SqliteConnection(connectionString);
            dbcon.Open();

            if(this.CheckTables() > 0) this.ready = true; //create our tables if they don't exist
        }
Пример #3
0
 public FDOperationLog(FDDataStore ds, FDLogVerbosity logVerbosity, bool toConsole)
 {
     DataStore = ds;
     verbosity = logVerbosity;
     console = toConsole;
 }
Пример #4
0
        //stores a message to the log table
        public int StoreLogMessage(FDLogVerbosity importance, string component, string smessage, string lmessage, DateTime timestamp)
        {
            int im = (int)importance; //cast to int for storage
            IDbCommand logInsert = dbcon.CreateCommand();

            logInsert.CommandText =
                "INSERT INTO log VALUES (NULL," +
                im.ToString() + "," +
                "\"" + component + "\"," +
                "\"" + smessage + "\"," +
                "\"" + lmessage + "\"," +
                timestamp.ToBinary().ToString() + ");";

            return logInsert.ExecuteNonQuery();
        }