Пример #1
0
        private List <Models.LogMsgGroup> SplitLogsToGroups(LogMsg[] messages)
        {
            Dictionary <string, Models.LogMsgGroup> groups = new Dictionary <string, LogMsgGroup>();

            foreach (var message in messages)
            {
                string groupKey = "default";

                if (message.AppDetails != null)
                {
                    groupKey = message.AppDetails.GetUniqueKey();
                }

                if (!groups.ContainsKey(groupKey))
                {
                    if (groupKey == "default" || message.AppDetails == null)
                    {
                        groups["default"] = CreateDefaultMsgGroup();
                    }
                    else
                    {
                        var defaults = CreateDefaultMsgGroup();

                        //default app, env, and server name if not set to whatever the current one is
                        //do not default the other fields as they not match what is being set.
                        //i.e. the default appnameid is not the correct id for a new custom app name being used.
                        var d     = message.AppDetails;
                        var group = new LogMsgGroup()
                        {
                            AppEnvID   = d.AppEnvID,
                            AppLoc     = d.AppLoc,
                            AppName    = d.AppName ?? defaults.AppName,
                            AppNameID  = d.AppNameID,
                            CDAppID    = d.CDAppID,
                            CDID       = d.CDID,
                            Env        = d.Env ?? defaults.Env,
                            EnvID      = d.EnvID,
                            Logger     = d.Logger ?? _LoggerName,
                            Platform   = ".net",
                            ServerName = d.ServerName ?? defaults.ServerName,
                            Msgs       = new List <LogMsg>()
                        };

                        groups[groupKey] = group;
                    }
                }

                groups[groupKey].Msgs.Add(message);
            }
            return(groups.Values.ToList());
        }
Пример #2
0
        private Models.LogMsgGroup CreateDefaultMsgGroup()
        {
            Models.LogMsgGroup group = new LogMsgGroup();
            //set these fields even if some could be null
            if (_HttpClient.AppIdentity != null)
            {
                group.CDAppID   = _HttpClient.AppIdentity.DeviceAppID;
                group.CDID      = _HttpClient.AppIdentity.DeviceID;
                group.EnvID     = _HttpClient.AppIdentity.EnvID;
                group.Env       = _HttpClient.AppIdentity.Env;
                group.AppNameID = _HttpClient.AppIdentity.AppNameID;
                group.AppEnvID  = _HttpClient.AppIdentity.AppEnvID;
                if (!String.IsNullOrWhiteSpace(_HttpClient.AppIdentity.DeviceAlias))
                {
                    group.ServerName = _HttpClient.AppIdentity.DeviceAlias;
                }

                if (!String.IsNullOrWhiteSpace(_HttpClient.AppIdentity.AppName))
                {
                    group.AppName = _HttpClient.AppIdentity.AppName;
                }
            }

            var env = EnvironmentDetail.Get();

            //We use whatever the identity stuff says, otherwise we use the azure instance name and fall back to the machine name
            if (string.IsNullOrEmpty(group.ServerName))
            {
                if (!string.IsNullOrEmpty(env.AzureInstanceName))
                {
                    group.ServerName = env.AzureInstanceName;
                }
                else
                {
                    group.ServerName = env.DeviceName;
                }
            }


            //if it wasn't set by the identity call above
            if (string.IsNullOrWhiteSpace(group.AppName))
            {
                group.AppName = env.AppNameToUse();
            }
            else if (group.AppName.StartsWith("/LM/W3SVC"))
            {
                group.AppName = env.AppNameToUse();
            }

            group.AppLoc = env.AppLocation;

            //override it
            if (!string.IsNullOrEmpty(env.ConfiguredEnvironmentName))
            {
                group.Env = env.ConfiguredEnvironmentName;
            }

            group.Logger   = _LoggerName;
            group.Platform = ".net";
            group.Msgs     = new List <LogMsg>();
            return(group);
        }