示例#1
0
        public static string GetStackEnvironmentInfo(AppInfo info, HeContext context)
        {
            AppInfoForStack     infoForStack    = FillAppInfoStruct(info, -1, -1);
            ContextInfoForStack contextForStack = FillContextInfoStruct(context);

            return(ErrorLogDefinition.GetStackEnvironmentInfo(infoForStack, contextForStack));
        }
示例#2
0
        public static string LogApplicationError(int espaceId, int tenantId, string message, Exception excep, string moduleName)
        {
            var infoForStack = new AppInfoForStack {
                espaceId = espaceId,
                tenantId = tenantId
            };

            return(LogApplicationError(DateTime.Now, message, excep, moduleName, excep.StackTrace, infoForStack, new ContextInfoForStack()));
        }
示例#3
0
        private static string LogApplicationError(DateTime instant, string message, Exception excep, AppInfo info, HeContext context, string moduleName,
                                                  string stackTrace, int overrideEspaceId, int overrideTenantId,
                                                  string overrideEspaceName = null, string overrideApplicationName = null, ObjectKey overrideApplicationKey = null)
        {
            visitsApplicationErrorLog = visitsApplicationErrorLog + 1;
            try {
                AppInfoForStack     infoForStack    = new AppInfoForStack();
                ContextInfoForStack contextForStack = new ContextInfoForStack();

                /* Prevent recursive loop attempt (#534214).
                 * 1st attempt tries to get info for logging (visitsApplicationErrorLog=1)
                 * 2nd attempt tries to log the new exception without getting info for logging (visitsApplicationErrorLog=2)
                 * 3rd attempt don't log the new exception to avoid recursive loops (visitsApplicationErrorLog>=3 */

                if (visitsApplicationErrorLog >= 3)
                {
                    return("");
                }

                /* Captain's Log #666 15:19 19/06/2017
                 * By now, we've concluded we can't properly refactor this without removing some information from our error logs.
                 * As of now, espace version id will no longer be logged on the second passing and we'll always try to fetch the
                 * context info(session id, user id and request tracer info) on the first and second passing, instead of only getting
                 * it at the first passing. To make this work, we must have sure that it never blows up. */
                if (visitsApplicationErrorLog < 2)
                {
                    infoForStack = FillAppInfoStruct(info, overrideEspaceId, overrideTenantId,
                                                     overrideEspaceName, overrideApplicationName, overrideApplicationKey);
                }

                contextForStack = FillContextInfoStruct(context);

                return(ErrorLogDefinition.LogApplicationError(instant, message, excep, moduleName, stackTrace, infoForStack, contextForStack));
            } finally {
                visitsApplicationErrorLog = visitsApplicationErrorLog - 1;
            }
        }
示例#4
0
        private static AppInfoForStack FillAppInfoStruct(AppInfo info, int overrideEspaceId, int overrideTenantId,
                                                         string overrideEspaceName = null, string overrideApplicationName = null, ObjectKey overrideApplicationKey = null)
        {
            AppInfoForStack infoForStack = new AppInfoForStack();

            if (info != null)
            {
                try { infoForStack.espaceId = info.eSpaceId; } catch { }
                try { infoForStack.tenantId = info.Tenant.Id; } catch { }
                try { infoForStack.espaceVersionId = info.eSpaceVersionId; } catch { }
                try { infoForStack.eSpaceName = info.eSpaceName; } catch { }
                try { infoForStack.applicationName = info.ApplicationName; } catch { }
                try { infoForStack.applicationKey = info.ApplicationUIDAsKey; } catch { }
                try { infoForStack.username = info.OsContext.Session.UserName; } catch { }
            }

            infoForStack.espaceId        = overrideEspaceId != -1 ? overrideEspaceId : infoForStack.espaceId;
            infoForStack.tenantId        = overrideTenantId != -1 ? overrideTenantId : infoForStack.tenantId;
            infoForStack.eSpaceName      = overrideEspaceName != null ? overrideEspaceName : infoForStack.eSpaceName;
            infoForStack.applicationName = overrideApplicationName != null ? overrideApplicationName : infoForStack.applicationName;
            infoForStack.applicationKey  = overrideApplicationKey != null ? overrideApplicationKey : infoForStack.applicationKey;

            return(infoForStack);
        }
示例#5
0
        public static string LogApplicationError(DateTime instant, string message, Exception excep, string moduleName, string stackTrace, AppInfoForStack info, ContextInfoForStack context)
        {
            try {
                if ((excep is HttpException) && ((excep.Message != null) && excep.Message.StartsWith("Error executing child request")) && (excep.InnerException != null))
                {
                    excep = excep.InnerException;
                }

                if (stackTrace != null)
                {
                    stackTrace = stackTrace.Replace(Environment.NewLine, ScriptableBuiltInFunction.NewLine());
                }

                string environmentInformation = GetStackEnvironmentInfo(info, context);
                string extraDetailMessage     = "";

                // try to generate full stack of the exception to see if we can fit all inner exceptions in a single error entry
                int countExceptions = 1;
                if (excep != null && excep.InnerException != null)
                {
                    stackTrace = GenerateFullStack(excep, out countExceptions);
                }

                StringBuilder stack = new StringBuilder();

                // create an error message dumping MAX_INNER_EXCEPTION_DEPTH inner exceptions if no stactTrace is provided
                int maxretries = (stackTrace != null) ? 1 : MAX_INNER_EXCEPTION_DEPTH;
                while ((excep != null && maxretries-- > 0) || stackTrace != null)
                {
                    extraDetailMessage = string.Empty;
                    if (stackTrace != null)
                    {
                        stack.Append(stackTrace); // if we are given the stacktrace as a whole, assume the message is also set or included
                        stackTrace = null;
                    }
                    else if (excep.StackTrace != null)
                    {
                        if (message.IsEmpty())
                        {
                            message = excep.Message ?? string.Empty;
                        }
                        else if (excep != null && excep.Message != null && !message.Contains(excep.Message))
                        {
                            extraDetailMessage = excep.Message + ScriptableBuiltInFunction.NewLine();
                        }

                        if (!message.IsEmpty())
                        {
                            stack.AppendLine(message);
                        }

                        if (!extraDetailMessage.IsEmpty())
                        {
                            stack.AppendLine(extraDetailMessage);
                        }

                        stack.Append(excep.StackTrace.Replace(Environment.NewLine, ScriptableBuiltInFunction.NewLine()));
                    }

                    // advance to the next inner exception
                    if (excep != null)
                    {
                        excep = excep.InnerException;
                    }
                }

                // log dumped inner exceptions stack trace
                return(ErrorLogDefinition.StaticWrite(instant, context.sessionId, info.espaceId, info.tenantId, context.userId, message, stack.ToString(),
                                                      environmentInformation, moduleName, context.requestKey, context.entryPointName, context.actionName,
                                                      info.eSpaceName, info.applicationName, info.applicationKey, context.username));
            } catch (Exception writeErrorException) {
                try {
                    ErrorLogDefinition.StaticWrite(DateTime.Now, context.sessionId, info.espaceId, info.tenantId, context.userId,
                                                   "Exception in Global.LogError:" + ScriptableBuiltInFunction.NewLine() + writeErrorException.Message,
                                                   writeErrorException.StackTrace, "Global", info.eSpaceName, info.applicationName, info.applicationKey, context.username);
                } catch { }
            }
            return(String.Empty);
        }
示例#6
0
        public static string GetStackEnvironmentInfo(AppInfoForStack info, ContextInfoForStack context)
        {
            // safely get all environment parameters
            string requestUrl = "", requestMethod = "", requestQuery = "", applicationPath = "", processName = "", processStartTime = "", currentLocale = "", filePath = "", dateFormat = "", dotNetVersion = "", appDomain = "", compiledWithVersion = "", clientIp = "", deviceUuid = "";
            int    espaceVersionId = 0, espaceVersion = 0, espaceVersionPublishingId = 0, processId = 0;
            long   privateMBytes = 0, virtualMBytes = 0, threadId = 0;
            string threadName = "";

            espaceVersionId = info.espaceVersionId;
            espaceVersion   = info.espaceVersion;

            requestUrl    = context.requestUrl;
            requestMethod = context.requestMethod;
            requestQuery  = context.requestQuery;
            currentLocale = context.currentLocale;
            clientIp      = context.clientIp;
            deviceUuid    = context.deviceUuid;

            try {
                applicationPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                applicationPath = applicationPath.Replace("Program Files\\OutSystems\\Service Center", "...\\SC")
                                  .Replace("Program Files\\OutSystems\\Platform Server", "...\\PS")
                                  .Replace("Program Files\\OutSystems\\Hub Server", "...\\HS");
            } catch { }

            try { privateMBytes = Process.GetCurrentProcess().PrivateMemorySize64 / 1024 / 1024; } catch { }

            try { virtualMBytes = Process.GetCurrentProcess().VirtualMemorySize64 / 1024 / 1024; } catch { }

            try { processId = Process.GetCurrentProcess().Id; } catch { }

            try { processName = Process.GetCurrentProcess().ProcessName; } catch { }

            try { processStartTime = Process.GetCurrentProcess().StartTime.ToUniversalTime().ToString(); } catch { }
            try { threadId = Thread.CurrentThread.ManagedThreadId; } catch { }

            try { threadName = Thread.CurrentThread.Name; } catch { }

            if (context.CurrentExecutionFileName != null)
            {
                filePath = ScriptableBuiltInFunction.NewLine() + "FilePath: " + applicationPath + context.CurrentExecutionFileName;
            }

            try { dateFormat = FormatInfoLogic.GetOutputDateFormatString(); } catch { }

            try { dotNetVersion = Environment.Version.ToString(); } catch { }

            try { appDomain = AppDomain.CurrentDomain.FriendlyName; } catch { }

            try { compiledWithVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); } catch { }

            string environmentInformation;

            if (EnvironmentInformationOverride != null)
            {
                environmentInformation = EnvironmentInformationOverride; // ScriptableBuiltInFunction.NewLine() + EnvironmentInformationOverride;
            }
            else
            {
                environmentInformation =
                    "eSpaceVer: " + espaceVersion + " (Id=" + espaceVersionId + ", PubId=" + espaceVersionPublishingId + ", CompiledWith=" + compiledWithVersion + ")" +
                    ScriptableBuiltInFunction.NewLine() + "RequestUrl: " + requestUrl + " (Method: " + requestMethod + ")" +
                    ScriptableBuiltInFunction.NewLine() + "AppDomain: " + appDomain +
                    ((filePath.IsNullOrEmpty()) ? ScriptableBuiltInFunction.NewLine() + "Path: " + applicationPath : filePath) +
                    ((clientIp.IsNullOrEmpty()) ? "" : (ScriptableBuiltInFunction.NewLine() + "ClientIp: " + clientIp)) +
                    ((deviceUuid.IsNullOrEmpty()) ? "" : (ScriptableBuiltInFunction.NewLine() + deviceUuid)) +
                    ScriptableBuiltInFunction.NewLine() + "Locale: " + currentLocale +
                    ScriptableBuiltInFunction.NewLine() + "DateFormat: " + dateFormat +
                    ScriptableBuiltInFunction.NewLine() + "PID: " + processId + " ('" + processName + "', Started='" + processStartTime + "', Priv=" + privateMBytes + "Mb, Virt=" + virtualMBytes + "Mb)" +
                    ScriptableBuiltInFunction.NewLine() + "TID: " + threadId +
                    ScriptableBuiltInFunction.NewLine() + "Thread Name: " + threadName +
                    ScriptableBuiltInFunction.NewLine() + ".NET: " + dotNetVersion;
            }

            return(environmentInformation);
        }