Esempio n. 1
0
File: Log.cs Progetto: igprog/ppweb
    public string LoadErrorLog(int?limit)
    {
        ErrorLogResponse response = new ErrorLogResponse();

        response.data = new List <NewErrorLog>();
        try {
            string path = HttpContext.Current.Server.MapPath("~/App_Data/" + usersDataBase);
            //DataBase db = new DataBase();
            //db.CreateGlobalDataBase(path, db.errorlog);
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + Server.MapPath("~/App_Data/" + usersDataBase))) {
                connection.Open();
                string sql = string.Format(@"SELECT e.errorLogId, e.id, e.userId, e.service, e.method, e.time, e.msg, e.stackTrace, u.userId, u.userGroupId, u.firstName, u.lastName, u.email
                            FROM errorlog e
                            LEFT JOIN users u
                            ON u.userId = e.userId ORDER BY e.rowid DESC {0}"
                                           , limit != null ? string.Format("LIMIT {0}", limit) : "");
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    using (SQLiteDataReader reader = command.ExecuteReader()) {
                        while (reader.Read())
                        {
                            NewErrorLog x = new NewErrorLog();
                            x.errorLogId       = reader.GetValue(0) == DBNull.Value ? null : reader.GetString(0);
                            x.id               = reader.GetValue(1) == DBNull.Value ? null : reader.GetString(1);
                            x.userId           = reader.GetValue(2) == DBNull.Value ? null : reader.GetString(2);
                            x.service          = reader.GetValue(3) == DBNull.Value ? null : reader.GetString(3);
                            x.method           = reader.GetValue(4) == DBNull.Value ? null : reader.GetString(4);
                            x.time             = reader.GetValue(5) == DBNull.Value ? null : reader.GetString(5);
                            x.msg              = reader.GetValue(6) == DBNull.Value ? null : reader.GetString(6);
                            x.stackTrace       = reader.GetValue(7) == DBNull.Value ? null : reader.GetString(7);
                            x.user             = new Users.NewUser();
                            x.user.userId      = reader.GetValue(8) == DBNull.Value ? null : reader.GetString(8);
                            x.user.userGroupId = reader.GetValue(9) == DBNull.Value ? null : reader.GetString(9);
                            x.user.firstName   = reader.GetValue(10) == DBNull.Value ? null : reader.GetString(10);
                            x.user.lastName    = reader.GetValue(11) == DBNull.Value ? null : reader.GetString(11);
                            x.user.email       = reader.GetValue(12) == DBNull.Value ? null : reader.GetString(12);
                            response.data.Add(x);
                        }
                    }
                }
            }
            Global G = new Global();
            response.dailyLogs = response.data.Where(a => G.DateDiff(a.time) < 1).Count();
            return(JsonConvert.SerializeObject(response, Formatting.None));
        } catch (Exception e) {
            SendErrorLog(e, null, null, "Log", "LoadErrorLog");
            return(JsonConvert.SerializeObject(response, Formatting.Indented));
        }
    }
Esempio n. 2
0
File: Log.cs Progetto: igprog/ppweb
    public void SendErrorLog(Exception e, string id, string userId, string service, string method)
    {
        NewErrorLog x = new NewErrorLog();
        Files       F = new Files();

        x.settings = F.GetSettingsData().errorLogSettings;

        x.id         = id;
        x.userId     = userId;
        x.service    = service;
        x.method     = method;
        x.time       = Global.NowLocal();
        x.msg        = e.Message;
        x.stackTrace = e.StackTrace;

        if (x.settings.showErorrLog)
        {
            string err = string.Format(@"## TIME: {0}
USER_ID: {1}
SERVICE: {2}.asmx\{3}
ID: {4}
MESSAGE: {5}
{6}
"
                                       , x.time.ToString()
                                       , x.userId
                                       , x.service
                                       , x.method
                                       , x.id
                                       , x.msg
                                       , x.settings.showStackTrace ? string.Format("STACK TRACE: {0}", e.StackTrace) : null);

            StringBuilder sb          = new StringBuilder();
            string        oldErrorLog = F.ReadTempFile(errorLog);
            if (oldErrorLog != null)
            {
                sb.AppendLine(oldErrorLog);
            }
            sb.AppendLine(err);
            F.SaveTempFile(errorLog, sb.ToString());
        }
        else if (x.settings.saveErorrLogDB)
        {
            SaveErrorLogDB(x);
        }
    }
Esempio n. 3
0
File: Log.cs Progetto: igprog/ppweb
 public void SaveErrorLogDB(NewErrorLog x)
 {
     try {
         Global G    = new Global();
         string path = HttpContext.Current.Server.MapPath("~/App_Data/" + usersDataBase);
         //DataBase db = new DataBase();
         //db.CreateGlobalDataBase(path, db.errorlog);
         if (string.IsNullOrWhiteSpace(x.errorLogId))
         {
             x.errorLogId = Guid.NewGuid().ToString();
         }
         string sql = string.Format(@"BEGIN;
                     INSERT OR REPLACE INTO errorlog (errorLogId, id, userId, service, method, time, msg, stackTrace)
                     VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}');
                     COMMIT;", x.errorLogId, x.id, x.userId, x.service, x.method, x.time, x.msg, x.stackTrace);
         using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + Server.MapPath("~/App_Data/" + usersDataBase))) {
             connection.Open();
             using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                 command.ExecuteNonQuery();
             }
         }
     } catch (Exception e) {
     }
 }