コード例 #1
0
        private NotepadEntity GetNotePadEntity(ErrorLogEntity errorLogEntity)
        {
            var notePadEntity = new NotepadEntity();

            notePadEntity.Name        = "ErrorLogs";
            notePadEntity.FilePath    = @"c:\Temp\Log\ErrorLogs.txt";
            notePadEntity.Description = "desc";
            notePadEntity.Contents    = $"ControllerName {errorLogEntity.ControllerName} StackTrace {errorLogEntity.StackTrace} TimeStamp {errorLogEntity.TimeStamp}";
            return(notePadEntity);
        }
コード例 #2
0
        public ErrorLogEntity ConvertToLoggerEntity(HttpActionExecutedContext filterContext)
        {
            var errorLogEntity = new ErrorLogEntity()
            {
                ControllerName = filterContext.Request.RequestUri.LocalPath,
                StackTrace     = filterContext.Exception.StackTrace,
                TimeStamp      = DateTime.Now.ToString()
            };

            return(errorLogEntity);
        }
コード例 #3
0
 public ActionResult Create()
 {
     if (ModelState.IsValid)
     {
         var entity = new ErrorLogEntity();
         return(View(entity));
         //return View();
     }
     else
     {
         return(View());
     }
 }
コード例 #4
0
        public ActionResult Edit(ErrorLogEntity entity)
        {
            try
            {
                tblOps.EditEntity(entity);
            }
            catch (System.Exception ex)
            {
                UserManager user = (UserManager)Session["CurrentUser"];
                LogHelper.AddLog(new LogEntity(AppConstant.PartitionError, user.EmailID.ToString(), AppConstant.ApplicationName, "ErrorLog, Edit", ex.Message, ex.StackTrace));
            }

            return(RedirectToAction("Index"));
        }
コード例 #5
0
        ///// <summary>
        ///// Creates a paged list of results from the ErrorLogEntity log
        ///// </summary>
        ///// <param name="pagedRequest">The request data containing page number and items per page</param>
        ///// <returns>A paged list of ErrorLogEntity models</returns>
        //public async Task<PagedList<ErrorLogModel>> GetErrorLogItems(ErrorLogRequest pagedRequest)
        //{
        //    var result = from ErrorLogEntity in this.loggingContext.ErrorLog select ErrorLogEntity;

        //    var filtered = result.OrderBy(o => o.Id);

        //    var pagedListCreator = new PagedResultFactory<ErrorLogEntity, ErrorLogModel>(pagedRequest);

        //    var pageListData = await pagedListCreator.CreatePageListDataAsync(filtered, CreateErrorLogModel);

        //    return pageListData;
        //}

        private static ErrorLogModel CreateErrorLogModel(ErrorLogEntity errorLogEntity)
        {
            var errorLogModel = new ErrorLogModel
            {
                Controller      = errorLogEntity.Controller,
                Action          = errorLogEntity.Action,
                UserId          = errorLogEntity.UserId,
                Message         = errorLogEntity.Message,
                RequestUrl      = errorLogEntity.RequestUrl,
                UserEmail       = errorLogEntity.UserEmail,
                CreatedDateTime = errorLogEntity.Timestamp.UtcDateTime
            };

            return(errorLogModel);
        }
コード例 #6
0
        /// <summary>
        /// Logs an ErrorLogEntity to the database
        /// </summary>
        /// <param name="errorLogModel">The class holding the ErrorLogEntity information</param>
        /// <returns>A result object</returns>
        public async Task <Response> LogError(ErrorLogModel errorLogModel)
        {
            var claimsIdentity = Thread.CurrentPrincipal.Identity as ClaimsIdentity;

            var error = new ErrorLogEntity
            {
                PartitionKey = errorLogModel.Controller,
                Id           = Guid.NewGuid().ToString("N"),
                Controller   = errorLogModel.Controller,
                Action       = errorLogModel.Action,
                UserEmail    = errorLogModel.UserEmail,
                UserId       = errorLogModel.UserId,
                Message      = errorLogModel.Message,
                Exception    = JsonConvert.SerializeObject(errorLogModel.Exception, Formatting.Indented),
                RequestUrl   = errorLogModel.RequestUrl
            };

            error.RowKey = error.Id;

            if (claimsIdentity != null)
            {
                var emailClaim = claimsIdentity.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email);

                if (emailClaim != null)
                {
                    error.UserEmail = emailClaim.Value;
                }

                var userIdClaim = claimsIdentity.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier);

                if (userIdClaim != null)
                {
                    error.UserId = userIdClaim.Value;
                }
            }

            try
            {
                await this.errorTableHandler.InsertAsync(error);

                return(Response.Success());
            }
            catch (Exception exp)
            {
                return(Response.Failed(exp.Message));
            }
        }
コード例 #7
0
 public void SubmitForm(Exception ex)
 {
     try
     {
         ErrorLogEntity errorLogEntity = new ErrorLogEntity();
         errorLogEntity.Date       = DateTime.Now;
         errorLogEntity.Message    = ex.Message;
         errorLogEntity.Source     = ex.Source;
         errorLogEntity.TargetSite = ex.TargetSite.Name;
         errorLogEntity.StackTrace = ex.StackTrace;
         service.Insert(errorLogEntity);
     }
     catch (Exception ex1)
     {
         throw;
     }
 }
コード例 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="oid"></param>
        /// <returns></returns>
        public ErrorLogModel GetById(string oid)
        {
            var result = default(ErrorLogModel);

            if (string.IsNullOrWhiteSpace(oid) ||
                oid == Guid.Empty.ToString() ||
                oid == Guid.Empty.ToString().Replace("-", string.Empty))
            {
                return(result);
            }

            ErrorLogEntity entity = null;

            using (var repo = new ErrorLogRepository <ErrorLogEntity>())
            {
                entity = repo
                         .FirstOrDefault(q => q.Id == oid, asNoTracking: true);
            }

            result = SimpleMapper.Map <ErrorLogEntity, ErrorLogModel>(entity);
            return(result);
        }
コード例 #9
0
 public ActionResult Create(ErrorLogEntity entity)
 {
     try
     {
         if (ModelState.IsValid)
         {
             tblOps.AddEntity(entity, AppConstant.PartitionError);
             //LogHelper.AddLog(new LogEntity(Constants.PARTITION_INFORMATIONLOG, HttpContext.User.Identity.Name.ToString(), ApplicationModules.CACHING, "New Configuration added for RedisCache"));
             return(RedirectToAction("Index"));
         }
         else
         {
             return(View());
         }
     }
     catch (System.Exception ex)
     {
         UserManager user = (UserManager)Session["CurrentUser"];
         LogHelper.AddLog(new LogEntity(AppConstant.PartitionError, user.EmailID.ToString(), AppConstant.ApplicationName, "ErrorLog, Create", ex.Message, ex.StackTrace));
         return(View());
     }
 }
コード例 #10
0
 public ErrorLogModel(ErrorLogEntity entity)
 {
     _errorOccurTime = entity.LogDate;
     _errorFlag      = entity.LogLevel;
     _errorContent   = entity.LogMessage;
 }
コード例 #11
0
        public static int UpdateErrorLog(string env, ErrorLogEntity errorLogEntity)
        {
            var connectionString = ConfigurationManager.ConnectionStrings[env].ConnectionString;

            var resultEntity = 0;

            using (var connection = new SqlConnection(connectionString))
            {
                using (var command = new SqlCommand("[UpdateErrorLog]")
                {
                    CommandType = CommandType.StoredProcedure, Connection = connection
                })
                {
                    // =====================================================================================================
                    // Add Parameters
                    // =====================================================================================================

                    if (errorLogEntity.ErrorLogId != null)
                    {
                        var param_ErrorLogId = new SqlParameter("@ErrorLogId", errorLogEntity.ErrorLogId)
                        {
                            Direction = ParameterDirection.Input, SqlDbType = System.Data.SqlDbType.Int
                        };
                        command.Parameters.Add(param_ErrorLogId);
                    }

                    if (errorLogEntity.ErrorNumber != null)
                    {
                        var param_ErrorNumber = new SqlParameter("@ErrorNumber", errorLogEntity.ErrorNumber)
                        {
                            Direction = ParameterDirection.Input, SqlDbType = System.Data.SqlDbType.Int
                        };
                        command.Parameters.Add(param_ErrorNumber);
                    }

                    if (errorLogEntity.ErrorSeverity != null)
                    {
                        var param_ErrorSeverity = new SqlParameter("@ErrorSeverity", errorLogEntity.ErrorSeverity)
                        {
                            Direction = ParameterDirection.Input, SqlDbType = System.Data.SqlDbType.Int
                        };
                        command.Parameters.Add(param_ErrorSeverity);
                    }

                    if (errorLogEntity.ErrorState != null)
                    {
                        var param_ErrorState = new SqlParameter("@ErrorState", errorLogEntity.ErrorState)
                        {
                            Direction = ParameterDirection.Input, SqlDbType = System.Data.SqlDbType.Int
                        };
                        command.Parameters.Add(param_ErrorState);
                    }

                    if (errorLogEntity.ErrorProcedure != null)
                    {
                        var param_ErrorProcedure = new SqlParameter("@ErrorProcedure", errorLogEntity.ErrorProcedure)
                        {
                            Direction = ParameterDirection.Input, SqlDbType = System.Data.SqlDbType.VarChar, Size = 126
                        };
                        command.Parameters.Add(param_ErrorProcedure);
                    }

                    //,@ErrorLine int = null
                    if (errorLogEntity.ErrorLine != null)
                    {
                        var param_ErrorLine = new SqlParameter("@ErrorLine", errorLogEntity.ErrorLine)
                        {
                            Direction = ParameterDirection.Input, SqlDbType = System.Data.SqlDbType.Int
                        };
                        command.Parameters.Add(param_ErrorLine);
                    }

                    //,@ErrorMessage varchar(2048) = ''
                    if (errorLogEntity.ErrorMessage != null)
                    {
                        var param_ErrorMessage = new SqlParameter("@ErrorMessage", errorLogEntity.ErrorMessage)
                        {
                            Direction = ParameterDirection.Input, SqlDbType = System.Data.SqlDbType.VarChar, Size = 2048
                        };
                        command.Parameters.Add(param_ErrorMessage);
                    }

                    //,@ErrorAdditionalInfo varchar(2048) = ''
                    if (errorLogEntity.ErrorAdditionalInfo != null)
                    {
                        var param_ErrorAdditionalInfo = new SqlParameter("@ErrorAdditionalInfo", errorLogEntity.ErrorAdditionalInfo)
                        {
                            Direction = ParameterDirection.Input, SqlDbType = System.Data.SqlDbType.VarChar, Size = 2048
                        };
                        command.Parameters.Add(param_ErrorAdditionalInfo);
                    }

                    //,@ExceptionHelpLink varchar(2048) = ''
                    if (errorLogEntity.ExceptionHelpLink != null)
                    {
                        var param_ExceptionHelpLink = new SqlParameter("@ExceptionHelpLink", errorLogEntity.ExceptionHelpLink)
                        {
                            Direction = ParameterDirection.Input, SqlDbType = System.Data.SqlDbType.VarChar, Size = 2048
                        };
                        command.Parameters.Add(param_ExceptionHelpLink);
                    }

                    //,@ExceptionTargetSite varchar(2048) = ''
                    if (errorLogEntity.ExceptionTargetSite != null)
                    {
                        var param_ExceptionTargetSite = new SqlParameter("@ExceptionTargetSite", errorLogEntity.ExceptionTargetSite)
                        {
                            Direction = ParameterDirection.Input, SqlDbType = System.Data.SqlDbType.VarChar, Size = 2048
                        };
                        command.Parameters.Add(param_ExceptionTargetSite);
                    }

                    //,@ExceptionMessage varchar(2048) = ''
                    if (errorLogEntity.ExceptionMessage != null)
                    {
                        var param_ExceptionMessage = new SqlParameter("@ExceptionMessage", errorLogEntity.ExceptionMessage)
                        {
                            Direction = ParameterDirection.Input, SqlDbType = System.Data.SqlDbType.VarChar, Size = 2048
                        };
                        command.Parameters.Add(param_ExceptionMessage);
                    }

                    //,@ExceptionStackTrace varchar(4096) = ''
                    if (errorLogEntity.ExceptionStackTrace != null)
                    {
                        var param_ExceptionStackTrace = new SqlParameter("@ExceptionStackTrace", errorLogEntity.ExceptionStackTrace)
                        {
                            Direction = ParameterDirection.Input, SqlDbType = System.Data.SqlDbType.VarChar
                        };
                        command.Parameters.Add(param_ExceptionStackTrace);
                    }


                    if (errorLogEntity.ExceptionSource != null)
                    {
                        var param_ExceptionSource = new SqlParameter("@ExceptionSource", errorLogEntity.ExceptionSource)
                        {
                            Direction = ParameterDirection.Input, SqlDbType = System.Data.SqlDbType.VarChar, Size = 4096
                        };
                        command.Parameters.Add(param_ExceptionSource);
                    }

                    //,@ExceptionAdditionalInfo varchar(2048) = ''
                    if (errorLogEntity.ExceptionAdditionalInfo != null)
                    {
                        var param_ExceptionAdditionalInfo = new SqlParameter("@ExceptionAdditionalInfo", errorLogEntity.ExceptionAdditionalInfo)
                        {
                            Direction = ParameterDirection.Input, SqlDbType = System.Data.SqlDbType.VarChar, Size = 2048
                        };
                        command.Parameters.Add(param_ExceptionAdditionalInfo);
                    }

                    if (errorLogEntity.UserId != null)
                    {
                        var param_UserId = new SqlParameter("@UserId", errorLogEntity.UserId)
                        {
                            Direction = ParameterDirection.Input, SqlDbType = System.Data.SqlDbType.Int
                        };
                        command.Parameters.Add(param_UserId);
                    }

                    //,@FriendlyMessage varchar(500) = ''
                    if (errorLogEntity.FriendlyMessage != null)
                    {
                        var param_FriendlyMessage = new SqlParameter("@FriendlyMessage", errorLogEntity.FriendlyMessage)
                        {
                            Direction = ParameterDirection.Input, SqlDbType = System.Data.SqlDbType.VarChar, Size = 500
                        };
                        command.Parameters.Add(param_FriendlyMessage);
                    }

                    // ==========================================================================================
                    // Standard parameters for success fail
                    // ==========================================================================================
                    var param_Return = new SqlParameter("@ReturnErrorLogId", System.Data.SqlDbType.Int)
                    {
                        Direction = ParameterDirection.Output
                    };
                    command.Parameters.Add(param_Return);
                    // ==========================================================================================

                    connection.Open();
                    command.ExecuteNonQuery();

                    resultEntity = (int)command.Parameters["@ReturnErrorLogId"].Value;
                }
            }

            return(resultEntity);
        }
コード例 #12
0
        public static List <ErrorLogEntity> GetErrorLogs(string env, int?tzOffsetMinutes, int?errorLogId, int?userId)
        {
            var connectionString = ConfigurationManager.ConnectionStrings[env].ConnectionString;

            var resultEntity = new List <ErrorLogEntity>();

            using (var connection = new SqlConnection(connectionString))
            {
                using (var command = new SqlCommand("[GetErrorLogs]")
                {
                    CommandType = CommandType.StoredProcedure, Connection = connection
                })
                {
                    // =====================================================================================================
                    // Add Parameters
                    // =====================================================================================================

                    //SqlParameter[] paramCollection = new SqlParameter[0];

                    if (userId != null)
                    {
                        var param_UserId = new SqlParameter("@UserId", userId)
                        {
                            Direction = ParameterDirection.Input,
                            SqlDbType = System.Data.SqlDbType.Int
                        };
                        command.Parameters.Add(param_UserId);
                    }

                    if (errorLogId != null)
                    {
                        var param_errorLogId = new SqlParameter("@errorLogId", errorLogId)
                        {
                            Direction = ParameterDirection.Input,
                            SqlDbType = System.Data.SqlDbType.Int
                        };
                        command.Parameters.Add(param_errorLogId);
                    }

                    connection.Open();
                    using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))
                    {
                        if (reader != null)
                        {
                            while (reader.Read())
                            {
                                var entity = new ErrorLogEntity();

                                entity.ErrorLogId              = NullHelper.GetInt32FromReader(reader, "ErrorLogId");
                                entity.ErrorNumber             = NullHelper.GetInt32FromReader(reader, "ErrorNumber");
                                entity.ErrorSeverity           = NullHelper.GetInt32FromReader(reader, "ErrorSeverity");
                                entity.ErrorState              = NullHelper.GetInt32FromReader(reader, "ErrorState");
                                entity.ErrorProcedure          = NullHelper.GetStringFromReader(reader, "ErrorProcedure");
                                entity.ErrorLine               = NullHelper.GetInt32FromReader(reader, "ErrorLine");
                                entity.ErrorMessage            = NullHelper.GetStringFromReader(reader, "ErrorMessage");
                                entity.ErrorAdditionalInfo     = NullHelper.GetStringFromReader(reader, "ErrorAdditionalInfo");
                                entity.ExceptionHelpLink       = NullHelper.GetStringFromReader(reader, "ExceptionHelpLink");
                                entity.ExceptionTargetSite     = NullHelper.GetStringFromReader(reader, "ExceptionTargetSite");
                                entity.ExceptionMessage        = NullHelper.GetStringFromReader(reader, "ExceptionMessage");
                                entity.ExceptionSource         = NullHelper.GetStringFromReader(reader, "ExceptionSource");
                                entity.ExceptionStackTrace     = NullHelper.GetStringFromReader(reader, "ExceptionStackTrace");
                                entity.ExceptionAdditionalInfo = NullHelper.GetStringFromReader(reader, "ExceptionAdditionalInfo");
                                entity.UserId          = NullHelper.GetInt32FromReader(reader, "UserId");
                                entity.FriendlyMessage = NullHelper.GetStringFromReader(reader, "FriendlyMessage");
                                entity.CreatedDateTime = NullHelper.GetDateFromReader(reader, "CreatedDateTime", tzOffsetMinutes);

                                resultEntity.Add(entity);
                            }
                        }
                    }
                }
            }

            return(resultEntity);
        }
コード例 #13
0
 /// <summary>
 /// Creates logs into a notepad
 /// </summary>
 /// <param name="errorLogEntity">ErrorLogEntity</param>
 /// <returns>ErrorLogEntity</returns>
 //public NotepadService CreateNotepadLogFolder ()
 //{
 //     notepadService.CreateNotePadLogFolder();
 //     ;
 //}
 public ErrorLogEntity CreateNotePadLog(ErrorLogEntity errorLogEntity)
 {
     notepadService.AppendInNotePad(GetNotePadEntity(errorLogEntity));
     return(errorLogEntity);
 }