Ejemplo n.º 1
0
        public EventReporterResponse RecordEvent(string AppID, General.ErrorLogging.Client.RecordEventDataContext Data)
        {
            if (Data == null)
            {
                throw new ArgumentNullException("No data specified, please POST the error data as a parent object with a valid AppContext and EventContext property.");
            }
            if (String.IsNullOrWhiteSpace(Data.AccessCode) || Data.AccessCode != Settings.APIWriteOnlyAccessCode)
            {
                if (!(User != null && User.Identity != null && User.Identity.IsAuthenticated))
                {
                    throw new UnauthorizedAccessException("Invalid Access Code");
                }
            }
            if (Data.AppContext.AppID == null)
            {
                throw new ArgumentNullException("AppContext.AppID is null, please POST the error data as a parent object with a valid AppContext property.");
            }
            if (Data.EventContext.EventName == null)
            {
                throw new ArgumentNullException("EventContext.EventName is null, please POST the error data as a parent object with a valid EventContext property.");
            }
            if (Data.AppContext.AppID.HasValue && Data.AppContext.AppID.Value != int.Parse(AppID))
            {
                throw new ArgumentException("AppID in API path doesn't match AppID specified in AppContext.");
            }

            Data.AppContext.AppID = int.Parse(AppID);
            var objResponse = General.ErrorLogging.Server.EventLogServer.StoreEventInDatabase(Data.EventContext, Data.AppContext, Data.FilterContext, Data.EventHistory);

            /*
             * //Process notifications
             * try
             * {
             *  NotificationController objNotifyController = new NotificationController();
             *  objNotifyController.BackgroundData = Data;
             *  objNotifyController.BackgroundIncidentCode = objResponse.IncidentCode;
             *  General.ErrorLogging.Threading.BackgroundWorker.RunInSeparateThread(new System.Threading.WaitCallback(objNotifyController.NotifyByFilterBackground));
             * }
             * catch { }
             */
            return(objResponse);
        }
Ejemplo n.º 2
0
        public static EventReporterResponse StoreEventInDatabase(EventContext exInfo, ApplicationContext context, FilterContext filterContext, EventHistoryContext historyContext = null)
        {
            if (context == null)
            {
                context = new ApplicationContext();
            }

            EventReporterResponse response = new EventReporterResponse();

            try
            {
                var enuEventType = General.ErrorLogging.Model.ErrorOtherTypes.Unknown;
                if (exInfo.EventType.HasValue)
                {
                    enuEventType = exInfo.EventType.Value;
                }

                string strAppName = "";
                try { strAppName = ErrorReporter.GetAppName(context); }
                catch { }

                try
                {
                    #region Send To Database
                    long intIncidentID = General.ErrorLogging.Data.ErrorOther.StoreEvent(ErrorReporter.GetAppID(context), ErrorReporter.GetEnvironment(context), context.ClientID
                                                                                         , enuEventType
                                                                                         , exInfo.Severity
                                                                                         , exInfo.ExceptionType
                                                                                         , exInfo.MethodName
                                                                                         , exInfo.FileName
                                                                                         , exInfo.LineNumber
                                                                                         , exInfo.ColumnNumber
                                                                                         , exInfo.ErrorCode
                                                                                         , exInfo.EventName
                                                                                         , exInfo.Details
                                                                                         , exInfo.URL
                                                                                         , exInfo.UserAgent
                                                                                         , context.UserType
                                                                                         , context.UserID
                                                                                         , context.CustomID
                                                                                         , strAppName
                                                                                         , context.MachineName
                                                                                         , context.Custom1 //Custom1
                                                                                         , context.Custom2 //Custom2
                                                                                         , context.Custom3 //Custom3
                                                                                         , exInfo.Duration //Duration
                                                                                         , filterContext
                                                                                         , historyContext);
                    response.Success    = true;
                    response.IncidentID = intIncidentID;
                    return(response);

                    #endregion
                }
                catch (Exception ex)
                {
                    try
                    {
                        General.ErrorLogging.Client.RecordEventDataContext request = new General.ErrorLogging.Client.RecordEventDataContext();
                        request.AppContext   = context;
                        request.EventContext = exInfo;

                        try
                        {
                            request.EventContext.Details += "\r\n\r\nError In Logging DLL (EventLogServer)\r\n" + General.Debugging.ErrorReporter.GetErrorReport(ex, "\r\n").ToString();
                        }
                        catch
                        {
                            request.EventContext.Details += "\r\n\r\nError In Logging DLL (EventLogServer)\r\n" + ex.Message;
                        }

                        General.ErrorLogging.Client.EventLogClient.EmailEvent(request, response);
                    }
                    catch { }
                    throw;
                }
            }
            catch (Exception ex)
            {
                //DON'T TRY TO REPORT THIS ERROR NORMALLY OR YOU COULD CREATE AN INFINITE LOOP AND CRASH THE APP
                try
                {
                    if (exInfo != null)
                    {
                        General.Debugging.Report.SendError("Error occurred while generating an error report.", System.Environment.CurrentDirectory + "\r\n\r\n" + exInfo.ErrorName + "\r\n\r\n" + ex.ToString() + "\r\n\r\n\r\n\r\n\r\n\r\n" + exInfo.Details.ToString());
                    }
                    else
                    {
                        General.Debugging.Report.SendError("Error occurred while generating an error report.", System.Environment.CurrentDirectory + "\r\n\r\n" + ex.ToString());
                    }
                }
                catch { }
            }
            return(response);
        }