Example #1
0
        public override TDto GetModel <TDto>(EntityBase domainEntity)
        {
            if (TypesEqual <TDto, ErrorLogDto>())
            {
                var logEntity = (Domain.Entity.ErrorLog.ErrorLog)domainEntity;

                var model = new ErrorLogDto
                {
                    Id                = logEntity.Id,
                    UserName          = logEntity.UserName,
                    ErrorDateTime     = logEntity.ErrorDateTime,
                    ErrorLevel        = logEntity.ErrorLevel,
                    ErrorMessage      = logEntity.ErrorMessage,
                    InnerErrorMessage = logEntity.InnerErrorMessage,
                    StackTrace        = logEntity.StackTrace
                };

                AddLinks(model, "ErrorLogRoute", "log");
                model.Links.Add(new Link
                {
                    Rel    = "User error logs - Administrators only",
                    Href   = Url.Link("UserErrorLogsRoute", new { userName = model.UserName }),
                    Method = "GET"
                });

                return(model as TDto);
            }
            return(null);
        }
Example #2
0
        public async Task <IActionResult> Post([FromBody] ErrorLogDto value)
        {
            _logger.LogError($"Type: {value.Type} \r\nMessage: {value.Message} \r\nCustom Message: {value.CustomMessage} \r\nPage: {value.Page} \r\nStack:{value.Stack}");

            await _service.SaveErrorLog(value);

            return(Ok());
        }
Example #3
0
        public async Task <ErrorLogDto> SaveErrorLog(ErrorLogDto errorLog)
        {
            ErrorLog map = _mapper.Map <ErrorLog>(errorLog);
            await _unitOfWork.ErrorLogs.AddAsync(map);

            await _unitOfWork.CommitAsync();

            return(_mapper.Map <ErrorLogDto>(map));
        }
Example #4
0
        /// <summary>
        /// 添加错误日志
        /// </summary>
        /// <param name="logDto"></param>
        /// <returns></returns>
        public async Task <int> AddErrorLogAsync(ErrorLogDto logDto)
        {
            var logEntity = logDto.MapTo <ErrorLogEntity>();

            baseService.Add(logEntity);
            var result = await baseService.SaveAsync();

            return(result);
        }
Example #5
0
 public static ErrorLog MapToModel(ErrorLogDto errorLog)
 {
     return(new ErrorLog
     {
         Date = errorLog.Date,
         Id = errorLog.Id,
         Message = errorLog.Message,
         StackTrace = errorLog.StackTrace
     });
 }
Example #6
0
 //[Route("writeExceptionLog")]
 public void WriteExceptionLog(ErrorLogDto model)
 {
     try
     {
         if (model.SecretKey == _projectSetting.Value.SecretKey)
         {
             _logService.WriteErrorLog(model);
         }
     }
     catch
     {
     }
 }
Example #7
0
        public ServiceReturnDto WriteErrorLog(ErrorLogDto log)
        {
            Sys_Error_Log entity = new Sys_Error_Log()
            {
                ActionName     = log.ActionName,
                ControllerName = log.ControllerName,
                HttpType       = log.HttpType,
                IPAddress      = log.IpAddress,
                UserID         = log.UserID,
                LoginName      = log.LoginName,
                Parameters     = log.Parameter,
                URL            = log.Url,
                SystemName     = log.SystemName,
                Message        = log.ErrorMessage
            };

            _unitOfWork.SysErrorLogRep.Insert(entity);
            return(null);
        }
Example #8
0
        // GET: /<controller>/
        public async Task <IActionResult> Index(ErrorLogOption filter)
        {
            ViewBag.filter = filter;
            var model       = new List <ErrorLogDto>();
            var contentRoot = Directory.GetCurrentDirectory();
            var webRoot     = Path.Combine(contentRoot, "logs\\Error");
            var filelist    = new List <string>();

            new ServiceCollection()
            .AddSingleton <IFileProvider>(new PhysicalFileProvider(webRoot))
            .AddSingleton <IFileManager, FileManager>()
            .BuildServiceProvider()
            .GetService <IFileManager>()
            .ShowStructure((layer, name) => filelist.Add(name));
            var result = new List <ErrorLogDto>();

            if (filelist.Count > 0)
            {
                int i = 1;
                foreach (var item in filelist.OrderByDescending(o => o))
                {
                    var m = new ErrorLogDto
                    {
                        Id          = i,
                        filename    = item,
                        CreatorTime = ZConvert.StrToDateTime(item.Replace(".log", ""), DateTime.Now)
                    };
                    result.Add(m);
                    i++;
                }
            }
            if (filter.kCreatorTime != null)
            {
                result = result.Where(o => o.CreatorTime >= filter.kCreatorTime.Value).ToList();
            }
            if (filter.eCreatorTime != null)
            {
                result = result.Where(o => o.CreatorTime <= filter.eCreatorTime.Value).ToList();
            }
            model = result.OrderByDescending(o => o.CreatorTime).ToList();
            return(View(model));
        }
Example #9
0
        public async Task Invoke(HttpContext context, IErrorLogService service)
        {
            try
            {
                await _next(context);
            }
            catch (RulesException re)
            {
                if (context.Response.HasStarted)
                {
                    throw;
                }

                context.Response.StatusCode = 400;
                context.Response.Headers.Add("exception", "validationException");
                var modelState = new ModelStateDictionary();
                re.AddModelStateErrors(modelState);
                var json = JsonConvert.SerializeObject(modelState.Errors(true), _jsonSettings);
                await context.Response.WriteAsync(json);
            }
            catch (CustomMessageException cm)
            {
                if (context.Response.HasStarted)
                {
                    throw;
                }

                object[] args = new object[2];

                args[0] = cm.Message;
                args[1] = cm.StackTrace;

                _logger.LogError(cm, "Exception: Message {0}, Stack {1}", args);

                ErrorLogDto value = new ErrorLogDto();

                value.CustomMessage = cm.ExceptionMessage;
                value.Message       = cm.Message;
                value.Page          = context.Request.Path;
                value.Stack         = cm.StackTrace;
                value.Type          = "Exception";

                await service.SaveErrorLog(value);

                context.Response.StatusCode  = 500;
                context.Response.ContentType = "application/json";
                context.Response.Headers.Add("exception", "messageException");
                var json = JsonConvert.SerializeObject(new { Message = cm.ExceptionMessage }, _jsonSettings);
                await context.Response.WriteAsync(json);
            }
            catch (Exception ex)
            {
                if (context.Response.HasStarted)
                {
                    throw;
                }

                int argCount = 3;

                if (ex.InnerException != null)
                {
                    argCount = 5;
                }

                object[] args = new object[argCount];

                args[0] = ex.Message;
                args[1] = ex.StackTrace;
                args[2] = context.Request.Path;

                if (ex.InnerException != null)
                {
                    args[3] = ex.InnerException.Message;
                    args[4] = ex.InnerException.StackTrace;
                    _logger.LogError(ex, "Exception: Message {0}, Stack {1}, Path {2}. Inner Exception: Message {3}, Stack {4}", args);
                }
                else
                {
                    _logger.LogError(ex, "Exception: Message {0}, Stack {1}, Path {2}", args);
                }

                ErrorLogDto value = new ErrorLogDto();

                value.CustomMessage = ex.Message;
                value.Message       = ex.Message;
                value.Page          = context.Request.Path;
                value.Stack         = ex.StackTrace;
                value.Type          = "Exception";

                await service.SaveErrorLog(value);

                context.Response.StatusCode  = 500;
                context.Response.ContentType = "application/json";
                context.Response.Headers.Add("exception", "messageException");

                object obj;

                if (ex.InnerException != null)
                {
                    obj = new { Message = ex.Message, Stack = ex.StackTrace, Path = context.Request.Path, InnerMessage = ex.InnerException.Message, InnerStack = ex.InnerException.StackTrace }
                }
                ;
                else
                {
                    obj = new { Message = ex.Message, Stack = ex.StackTrace, Path = context.Request.Path }
                };

                var json = JsonConvert.SerializeObject(obj, _jsonSettings);
                await context.Response.WriteAsync(json);
            }
        }
    }
Example #10
0
 public void Create(ErrorLogDto errorLogDto)
 {
     _repositoryErrorLog.Create(Mapper.Map <Entity.ErrorLog>(errorLogDto));
     _repositoryErrorLog.Save();
 }