コード例 #1
0
        private static ContextInfoForStack FillContextInfoStruct(HeContext context)
        {
            ContextInfoForStack contextForStack = new ContextInfoForStack();

            if (context != null)
            {
                try { contextForStack.sessionId = context.Session.SessionID; } catch { }
                try { contextForStack.userId = context.Session.UserId; } catch { }
                try { contextForStack.username = context.Session.UserName; } catch { }
                try {
                    if (context.RequestTracer != null)
                    {
                        RequestTracer requestTracer = context.RequestTracer;
                        contextForStack.requestKey     = requestTracer.RequestKey;
                        contextForStack.actionName     = requestTracer.EntryActionName;
                        contextForStack.entryPointName = requestTracer.EntryEndpointName;
                        requestTracer.RegisterError();
                    }
                } catch { }
                try { contextForStack.requestUrl = context.Context.Request.Url.ToString(); } catch { }
                try { contextForStack.requestMethod = context.Context.Request.HttpMethod; } catch { }
                try {
                    contextForStack.requestQuery = context.Context.Request.QueryString != null?context.Context.Request.QueryString.ToString() : "";
                } catch { }
                try { contextForStack.currentLocale = context.CurrentLocale; } catch { }
                try { contextForStack.clientIp = RuntimePlatformUtils.GetClientIpForLogging(); } catch { }
                try { contextForStack.deviceUuid = RuntimePlatformUtils.GetDeviceUuidForLogging(); } catch { }
                try { contextForStack.CurrentExecutionFileName = context.CurrentExecutionFileName; } catch { }
            }

            return(contextForStack);
        }
コード例 #2
0
        public static string GetStackEnvironmentInfo(AppInfo info, HeContext context)
        {
            AppInfoForStack     infoForStack    = FillAppInfoStruct(info, -1, -1);
            ContextInfoForStack contextForStack = FillContextInfoStruct(context);

            return(ErrorLogDefinition.GetStackEnvironmentInfo(infoForStack, contextForStack));
        }
コード例 #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
        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);
        }
コード例 #5
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);
        }