public async Task <IActionResult> Log(LogAddressModel model) { var appid = _tokenManager.ValidateAccessToken(model.AccessToken); var appLocal = await _dbContext.ObserverApps.SingleOrDefaultAsync(t => t.AppId == appid); if (appLocal == null) { appLocal = new ObserverApp { AppId = appid }; await _dbContext.ObserverApps.AddAsync(appLocal); await _dbContext.SaveChangesAsync(); } var newEvent = new ErrorLog { AppId = appid, Message = model.Message, StackTrace = model.StackTrace, EventLevel = model.EventLevel, Path = model.Path }; await _dbContext.ErrorLogs.AddAsync(newEvent); await _dbContext.SaveChangesAsync(); return(this.Protocol(ErrorType.Success, "Successfully logged your event.")); }
private async Task AllClean(ObserverDbContext dbContext) { var oldestRecordTime = DateTime.UtcNow - TimeSpan.FromDays(7); var items = await dbContext.ErrorLogs.Where(t => t.LogTime < oldestRecordTime).ToListAsync(); dbContext.ErrorLogs.RemoveRange(items); await dbContext.SaveChangesAsync(); }
public async Task <IActionResult> DeleteApp(DeleteAppAddressModel model) { var appid = _tokenManager.ValidateAccessToken(model.AccessToken); if (appid != model.AppId) { return(this.Protocol(ErrorType.Unauthorized, "The app you try to delete is not the access token you granted!")); } _dbContext.ErrorLogs.Delete(t => t.AppId == appid); await _dbContext.SaveChangesAsync(); return(this.Protocol(ErrorType.Success, "App deleted.")); }