Exemplo n.º 1
0
        private void Write(IAppInfo appInfo, ISessionInfo sessionInfo, DateTime instant, int duration, string screen, string msisdn,
                           string screenType, string accessMode, string executedBy, int viewstateBytes, int sessionBytes, int sessionRequests)
        {
            Instant         = instant;
            Duration        = duration;
            Screen          = screen;
            SessionId       = sessionInfo.SessionID;
            EspaceId        = appInfo.eSpaceId;
            TenantId        = appInfo.TenantId;
            UserId          = sessionInfo.UserId;
            Msisdn          = msisdn;
            ScreenType      = screenType;
            AccessMode      = ScreenLogDefinition.NotNullAccessMode(accessMode);
            ExecutedBy      = executedBy;
            ViewstateBytes  = viewstateBytes;
            SessionBytes    = sessionBytes;
            SessionRequests = sessionRequests;

            RequestTracer reqTracer = RuntimePlatformUtils.GetRequestTracer();

            if (reqTracer != null)
            {
                RequestKey = reqTracer.RequestKey;
                ActionName = reqTracer.EntryActionName;
            }

            ClientIP        = RuntimePlatformUtils.GetRequestSourceForLogging()?.Left(MAX_CLIENT_IP_SIZE);
            EspaceName      = appInfo.eSpaceName;
            ApplicationName = appInfo.ApplicationName;
            ApplicationKey  = appInfo.ApplicationUIDAsKey;
            Username        = sessionInfo.UserName;

            log.Write();
        }
Exemplo n.º 2
0
        public GeneralLog(DateTime instant, string sessionId, int espaceId, int tenantId, int userId, string message, string messageType, string moduleName, string errorId)
        {
            string requestKey, actionName, entryPointName, clientIp;

            requestKey = actionName = entryPointName = clientIp = String.Empty;

            RequestTracer reqTracer = RuntimePlatformUtils.GetRequestTracer();

            if (reqTracer != null)
            {
                requestKey     = reqTracer.RequestKey;
                actionName     = reqTracer.EntryActionName;
                entryPointName = reqTracer.EntryEndpointName;
            }
            clientIp = RuntimePlatformUtils.GetRequestSourceForLogging();

            GetEspaceDetails(espaceId, userId, out string eSpaceName, out string applicationName, out ObjectKey applicationKey, out string username);

            log = new GeneralLogDefinition(instant, sessionId, espaceId, tenantId, userId, message, messageType, moduleName,
                                           errorId, requestKey, actionName, entryPointName, clientIp,
                                           eSpaceName, applicationName, applicationKey, username);
        }
Exemplo n.º 3
0
        public void Write(DateTime instant, string sessionId, int espaceId, int tenantId, int userId,
                          string message, string messageType, string moduleName, string errorId,
                          string eSpaceName, string applicationName, ObjectKey applicationKey, string username)
        {
            string requestKey     = RequestKey;
            string actionName     = ActionName;
            string entryPointName = EntrypointName;
            string clientIp       = ClientIP;

            RequestTracer reqTracer = RuntimePlatformUtils.GetRequestTracer();

            if (reqTracer != null)
            {
                requestKey     = reqTracer.RequestKey;
                actionName     = reqTracer.EntryActionName;
                entryPointName = reqTracer.EntryEndpointName;
            }
            clientIp = RuntimePlatformUtils.GetRequestSourceForLogging();

            log.Write(instant, sessionId, espaceId, tenantId, userId, message, messageType, moduleName,
                      errorId, requestKey, actionName, entryPointName, clientIp,
                      eSpaceName, applicationName, applicationKey, username);
        }
Exemplo n.º 4
0
        public static void LogResponse(HttpActionExecutedContext actionExecutedContext, string errorId = null)
        {
            if (actionExecutedContext == null || actionExecutedContext.Response == null)
            {
                return;
            }

            AppInfo           appInfo           = AppInfo.GetAppInfo();
            HttpContext       context           = appInfo.Context;
            RESTExposeContext restExposeContext = GetLoggingContext();

            if (restExposeContext != null &&
                !restExposeContext.AlreadyLogged &&
                ((!string.IsNullOrEmpty(restExposeContext.ErrorLogId) || (!appInfo.SelectiveLoggingEnabled || appInfo.Properties.AllowLogging)) && restExposeContext.LogRequest))
            {
                TimeSpan duration     = DateTime.Now.Subtract(restExposeContext.StartTime);
                int      eSpaceId     = appInfo.eSpaceId;
                int      tenantId     = appInfo.Tenant?.Id ?? 0;
                string   errorIdToLog = errorId ?? restExposeContext.ErrorLogId;
                string   source       = RuntimePlatformUtils.GetRequestSourceForLogging();
                string   id           = null;

                if (restExposeContext.LogTo == LogTo.RESTExpose)
                {
                    id = IntegrationLog.StaticWrite(appInfo, DateTime.Now, (int)duration.TotalMilliseconds, source, null, restExposeContext.ServiceName + "." + restExposeContext.ActionName, "REST (Expose)", errorIdToLog, true);
                }
                else
                {
                    HeContext heContext = appInfo.OsContext;
                    string    loginId   = heContext?.Session?.NewRuntimeLoginInfo?.LoginId ?? string.Empty;
                    int       userId    = heContext?.Session?.NewRuntimeLoginInfo?.UserId ?? 0;
                    string    username  = heContext?.Session?.NewRuntimeLoginInfo?.Username ?? string.Empty;

                    if (userId == 0)
                    {
                        userId   = restExposeContext.RequesterUserId;
                        username = restExposeContext.RequesterUsername;
                        loginId  = restExposeContext.RequesterLoginId;
                    }

                    if (restExposeContext.LogTo == LogTo.ScreenServices)
                    {
                        id = MobileRequestLog.StaticWrite(appInfo, DateTime.Now, restExposeContext.ScreenName, restExposeContext.ActionName, source, (int)duration.TotalMilliseconds, RuntimeEnvironment.MachineName, errorIdToLog, loginId, userId, username);
                    }
                    else if (restExposeContext.LogTo == LogTo.ServiceAPIs)
                    {
                        id = ServiceAPILog.StaticWrite(
                            appInfo: appInfo,
                            sessionInfo: heContext?.Session,
                            instant: DateTime.Now,
                            loginId: loginId,
                            errorId: errorIdToLog,
                            executedBy: RuntimeEnvironment.MachineName,
                            action: restExposeContext.ServiceAPIMethodName,
                            duration: (int)duration.TotalMilliseconds,
                            source: source,
                            endpoint: Path.Combine(appInfo.eSpaceName, "ServiceAPI", restExposeContext.ServiceAPIMethodName),
                            originalRequestKey: restExposeContext.OriginalRequestKey
                            );
                    }
                }

                bool withError = !string.IsNullOrEmpty(errorIdToLog);

                if (actionExecutedContext != null && restExposeContext.RequestTrace != null && (restExposeContext.TraceAll || (restExposeContext.TraceErrors && withError)))
                {
                    StringBuilder responseTrace = new StringBuilder();
                    responseTrace.AppendLine(context.Request.ServerVariables["SERVER_PROTOCOL"] + " " + ((int)actionExecutedContext.Response.StatusCode).ToString() + " " + actionExecutedContext.Response.ReasonPhrase);
                    WriteResponseHeaders(responseTrace, context, actionExecutedContext);

                    if (actionExecutedContext.Response != null && actionExecutedContext.Response.Content != null)
                    {
                        if (!restExposeContext.IsResponseBinary)
                        {
                            try {
                                byte[]   content         = actionExecutedContext.Response.Content.ReadAsByteArrayAsync().Result;
                                string   charset         = RestServiceHttpUtils.TryGetResponseEncoding(actionExecutedContext.Response, DefaultEncoding);
                                Encoding requestEncoding = Encoding.GetEncoding(charset);
                                responseTrace.AppendLine(requestEncoding.GetString(content));
                            } catch {
                                WriteBinaryData(responseTrace);
                            }
                        }
                        else
                        {
                            WriteBinaryData(responseTrace);
                        }
                    }

                    int    tenantIdToDetailLog = (appInfo.Tenant != null ? appInfo.Tenant.Id : 0);
                    string detail      = $"{restExposeContext.RequestTrace}\n\n{responseTrace.ToString()}";
                    string detailLabel = "HTTP Trace";

                    StaticDetailLog(restExposeContext.LogTo, id, DateTime.Now, tenantIdToDetailLog, string.Empty, detail, detailLabel);
                }

                restExposeContext.AlreadyLogged = true;
            }
        }