public static async Task <EventReporterResponse> StoreEvent(Model.ErrorOther model, ApplicationContext appContext, FilterContext filterContext = null, EventHistoryContext historyContext = null)
        {
            try
            {
                EventReporterResponse result = new EventReporterResponse();
                if (ErrorReporter.ErrorLogUseSQLConnToReport)
                {
                    //Read the AppContext into the model
                    if (appContext.AppID.HasValue)
                    {
                        model.AppID = appContext.AppID.Value;
                    }
                    model.AppName     = appContext.AppName;
                    model.ClientID    = appContext.ClientID;
                    model.Custom1     = appContext.Custom1;
                    model.Custom2     = appContext.Custom2;
                    model.Custom3     = appContext.Custom3;
                    model.CustomID    = appContext.CustomID;
                    model.Environment = ErrorReporter.GetEnvironment(appContext);
                    model.MachineName = appContext.MachineName;
                    model.UserID      = appContext.UserID;
                    model.UserType    = appContext.UserType;

                    //Talk to database
                    try
                    {
                        result = General.ErrorLogging.Server.EventLogServer.StoreEventInDatabase(model, appContext, filterContext, historyContext);
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                }
                else
                {
                    //Read the model into an EventContext
                    EventContext eventContext = new EventContext(model);

                    //Prepare Web Service request
                    RecordEventDataContext request = new RecordEventDataContext();
                    request.AccessCode    = ErrorReporter.ErrorAPIWriteOnlyAccessCode;
                    request.AppContext    = appContext;
                    request.EventContext  = eventContext;
                    request.FilterContext = filterContext;
                    request.EventHistory  = historyContext;

                    //Make Web Service Call
                    result = await StoreEvent(request).ConfigureAwait(false);
                }
                return(result);
            }
            catch
            {
                throw;
            }
        }
Пример #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);
        }
Пример #3
0
 public void TestGetEnvironment(string informationalVersion, string environment)
 {
     Assert.That(ErrorReporter.GetEnvironment(informationalVersion), Is.EqualTo(environment));
 }