Beispiel #1
0
 private LogInfo LogInfoFromDataReader(SqlDataReader rdr)
 {
     var log = new LogInfo();
     log.Id = rdr.GetInt32(rdr.GetOrdinal("Id"));
     log.ChannelId = rdr.GetInt32(rdr.GetOrdinal("ChannelId"));
     if (!rdr.IsDBNull(rdr.GetOrdinal("UserUid")))
         log.UserUid = rdr.GetString(rdr.GetOrdinal("UserUid"));
     log.Title = rdr.GetString(rdr.GetOrdinal("Title"));
     log.Message = rdr.GetString(rdr.GetOrdinal("Message"));
     log.Level = rdr.GetString(rdr.GetOrdinal("Level"));
     if (!rdr.IsDBNull(rdr.GetOrdinal("StackTrace")))
         log.StackTrace = rdr.GetString(rdr.GetOrdinal("StackTrace"));
     log.LogTime = DateTime.SpecifyKind(rdr.GetDateTime(rdr.GetOrdinal("LogTime")), DateTimeKind.Local);
     return log;
 }
Beispiel #2
0
 public void Log(LogInfo log)
 {
     using (var con = new SqlConnection(ConfigHelp.ConnectionString))
     {
         con.Open();
         var cmd = con.CreateCommand();
         cmd.CommandText = @"insert into LogInfo (ChannelId,UserUid,Title,Message,StackTrace,Level,LogTime)
     values (@ChannelId,@UserUid,@Title,@Message,@StackTrace,@Level,@LogTime)";
         cmd.Parameters.Add(new SqlParameter("@ChannelId", log.ChannelId));
         cmd.Parameters.Add(new SqlParameter("@UserUid", log.UserUid ?? (object)DBNull.Value));
         cmd.Parameters.Add(new SqlParameter("@Title", log.Title));
         cmd.Parameters.Add(new SqlParameter("@Message", log.Message));
         cmd.Parameters.Add(new SqlParameter("@StackTrace", log.StackTrace ?? (object)DBNull.Value));
         cmd.Parameters.Add(new SqlParameter("@Level", log.Level));
         cmd.Parameters.Add(new SqlParameter("@LogTime", log.LogTime));
         cmd.ExecuteNonQuery();
     }
 }
 private static void LogPushResultToDatabase(PushContext context, string message, Exception ex)
 {
     var log = new LogInfo();
     log.ChannelId = context.Subscription.ChannelId;
     log.UserUid = context.Subscription.UserUid;
     log.Message = message;
     if (ex == null)
     {
         log.Title = "推送成功";
         log.Level = LogInfo.LEVEL_INFO;
     }
     else
     {
         log.Title = "推送失败";
         log.Level = LogInfo.LEVEL_WARN;
         log.StackTrace = ex.StackTrace;
     }
     log.LogTime = DateTime.Now;
     try
     {
         PushBo.Instance.Log(log);
     }
     catch (Exception e)
     {
         Logger.Log.Error(e);
     }
 }