コード例 #1
0
        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."));
        }
コード例 #2
0
        public async Task <IActionResult> View(ViewAddressModel 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 logs = (await _dbContext
                        .ErrorLogs
                        .Where(t => t.AppId == appid)
                        .ToListAsync())
                       .GroupBy(t => t.Message)
                       .Select(t => new LogCollection
            {
                Message = t.Key,
                First   = t.OrderByDescending(p => p.LogTime).FirstOrDefault(),
                Count   = t.Count()
            })
                       .ToList();
            var viewModel = new ViewLogViewModel
            {
                AppId   = appLocal.AppId,
                Logs    = logs,
                Code    = ErrorType.Success,
                Message = "Successfully get your logs!"
            };

            return(Ok(viewModel));
        }