LogRecord API

LogRecord stores two types of logs.

SMP101DB.GetLogger – gets the log API. The client can write its own records using the log API. For example:
ILogger logger = SMP101DB.GetLogger();
    logger.Debug("Write this string to the log records table");
    SMP101DB.SubmitLogRecords();
SMP101DB.GetLogRecords – gets the log records received from the server. For example:
Query query = new Query();
query.TestCriteria = Sybase.Persistence.AttributeTest.Equal("component", "Customer");
Sybase.Persistence.SortCriteria sortCriteria = new Sybase.Persistence.SortCriteria();         
sortCriteria.Add("requestId", Sybase.Persistence.SortOrder.DESCENDING);           
query.SortCriteria = sortCriteria;

GenericList<ILogRecord> loglist = SMP101DB.GetLogRecords(query);

This sample code shows how to find the corresponding MBO with the LogRecord and to delete the log record when a record is processed.

private void processLogRecords()
  {
    Query query = new Query();
    GenericList<ILogRecord> logRecords = SMP101DB.GetLogRecords(query);
    foreach (ILogRecord log in logRecords)
    {
      // log warning message
      BenchmarkUtils.AddInfo("log " + log.Component + ":" 
      + log.EntityKey
	  + " code:" + log.Code
      + " msg:" + log.Message);
			
      if (log.Component.Equals("Customer"))
      {
        long surrogateKey = Convert.ToInt64(log.EntityKey);
	    Customer c = Customer.Find(surrogateKey);
	    if (c.IsPending)
	    {
	       c.CancelPending();
	    }
				
	    log.Delete();
	    log.SubmitPending();
      }
   }
		
   SMP101DB.BeginSynchronize(null, null);
}
A LogRecord is not generated for a successful operation replay. SAP Mobile Server only creates one when an operation fails or completes with warnings. The client is responsible for removing operation replay log records. SAP Mobile Server typically allows a period of time for the client to download and act on the operation replay log record. Therefore, the client should proactively remove these log records when they are consumed. Failure to do so may result in accumulation of operation replay log records until SAP Mobile Server removes them. This sample code illustrates how to find the corresponding MBO with the LogRecord and delete the log record when it is processed.
private void processLogs() 
{ 
   Query query = new Query(); 
   GenericList<LogRecord> logRecords = SMP101DB.getLogRecords(query); 
   for(LogRecord log : logRecords) 
   { 
      // log warning message 
      Log.warning("log " + log.getComponent() 
      + ":" + log.getEntityKey() 
      + " code:" + log.getCode() + " msg:" + log.getMessage()); 

      if (log.getComponent().equals("Customer")) 
      { 
         long surrogateKey = Long.parseLong(log.getEntityKey()); 
         Customer c = Customer.find(surrogateKey); 
         if (c.isPending()) 
         { 
            c.cancelPending(); 
         } 

         // delete the LogRecord after it is processed 
         log.delete(); 
         log.submitPending(); 
      } 
   }
SAP Mobile Server is responsible for deleting client log records uploaded by the application. These application logs are used for audit and/or support services. Determine and set the retention policy from SAP Control Center after consulting with the application's developers. If there are multiple applications using the same package, retain them based on the maximum required time for each application. Client log records are removed that are outside the retention window, and deleted records removed from the client database the next time the application synchronizes. See Improve Synchronization Performance by Reducing the Log Record Size in Troubleshooting for details about reducing the Log Record size.