예제 #1
0
        public async Task <Response> PostLogEntry([FromBody] LogEntryTranfer logEntryTranfer)
        {
            if (!ModelState.IsValid)
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.ModeloInvalido,
                });
            }

            try
            {
                var logLevelID    = db.LogLevels.FirstOrDefault(l => l.ShortName.Contains(logEntryTranfer.LogLevelShortName)).LogLevelId;
                var logCategoryID = db.LogCategories.FirstOrDefault(l => l.ParameterValue.Contains(logEntryTranfer.LogCategoryParametre)).LogCategoryId;

                db.Add(new LogEntry
                {
                    UserName        = logEntryTranfer.UserName,
                    ApplicationName = logEntryTranfer.ApplicationName,
                    ExceptionTrace  = (logEntryTranfer.ExceptionTrace != null) ? LogEntryHelper.GetAllErrorMsq(logEntryTranfer.ExceptionTrace) : null,
                    LogCategoryId   = logCategoryID,
                    LogLevelId      = logLevelID,
                    LogDate         = DateTime.Now,
                    MachineIP       = LogNetworkHelper.GetRemoteIpClientAddress(),
                    MachineName     = LogNetworkHelper.GetClientMachineName(),
                    Message         = logEntryTranfer.Message,
                    ObjEntityId     = logEntryTranfer.EntityID
                });
                await db.SaveChangesAsync();

                return(new Response
                {
                    IsSuccess = true,
                    Message = Mensaje.Satisfactorio,
                });
            }
            catch (Exception ex)
            {
                await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                {
                    ApplicationName      = Convert.ToString(Aplicacion.Logs),
                    ExceptionTrace       = ex,
                    Message              = Mensaje.Excepcion,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Critical),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    UserName             = "",
                });

                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.Error,
                });
            }
        }
예제 #2
0
        public async Task <IActionResult> PostLogEntry([FromBody] JObject form)
        {
            //logEntry.ExceptionTrace = new Exception();
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}
            try
            {
                dynamic logEntryForm = form;

                var logEntry = new LogEntryTranfer
                {
                    LogCategoryParametre = logEntryForm.LogCategoryParametre,
                    LogLevelShortName    = logEntryForm.LogLevelShortName,
                };

                var logLevelID    = db.LogLevels.FirstOrDefault(l => l.ShortName.Contains(logEntry.LogLevelShortName)).LogLevelId;
                var logCategoryID = db.LogCategories.FirstOrDefault(l => l.ParameterValue.Contains(logEntry.LogCategoryParametre)).LogCategoryId;

                if (logLevelID.Equals(null) || logCategoryID.Equals(null))
                {
                    return(BadRequest());
                }

                db.Add(new LogEntry
                {
                    UserName        = logEntryForm.UserName,
                    ApplicationName = logEntryForm.ApplicationName,
                    ExceptionTrace  = (logEntry.ExceptionTrace != null) ? LogEntryHelper.GetAllErrorMsq(logEntry.ExceptionTrace) : null,
                    LogCategoryId   = logCategoryID,
                    LogLevelId      = logLevelID,
                    LogDate         = DateTime.Now,
                    MachineIP       = LogNetworkHelper.GetRemoteIpClientAddress(),
                    MachineName     = LogNetworkHelper.GetClientMachineName(),
                    Message         = logEntryForm.Message,
                    ObjEntityId     = logEntryForm.EntityID
                });
                await db.SaveChangesAsync();

                return(Ok("Ok"));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
예제 #3
0
        public async Task <Response> PostLogEntry([FromBody] LogEntryTranfer logEntryTranfer)
        {
            if (!ModelState.IsValid)
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = "MÓDELO INVÁLIDO",
                });
            }

            try
            {
                var logLevelID    = db.LogLevels.FirstOrDefault(l => l.ShortName.Contains(logEntryTranfer.LogLevelShortName)).LogLevelId;
                var logCategoryID = db.LogCategories.FirstOrDefault(l => l.ParameterValue.Contains(logEntryTranfer.LogCategoryParametre)).LogCategoryId;

                db.Add(new LogEntry
                {
                    UserName        = logEntryTranfer.UserName,
                    ApplicationName = logEntryTranfer.ApplicationName,
                    ExceptionTrace  = (logEntryTranfer.ExceptionTrace != null) ? LogEntryHelper.GetAllErrorMsq(logEntryTranfer.ExceptionTrace) : null,
                    LogCategoryId   = logCategoryID,
                    LogLevelId      = logLevelID,
                    LogDate         = DateTime.Now,
                    MachineIP       = LogNetworkHelper.GetRemoteIpClientAddress(),
                    MachineName     = LogNetworkHelper.GetClientMachineName(),
                    Message         = logEntryTranfer.Message,
                    ObjEntityId     = logEntryTranfer.EntityID
                });
                await db.SaveChangesAsync();

                return(new Response
                {
                    IsSuccess = true,
                    Message = "Ok",
                });
            }
            catch (Exception ex)
            {
                return(new  Response
                {
                    IsSuccess = false,
                    Message = ex.Message,
                });
            }
        }