Esempio n. 1
0
        protected Guid Log(MessageType type,
                           string from,
                           string message,
                           Exception error       = null,
                           Guid?relatedMessageID = null,
                           string parameters     = null)
        {
            if (type < ComponentDirector.LogLevel)
            {
                return(Guid.Empty);
            }

            var logMessage = new Log.Message
            {
                Topic      = LOG_TOPIC,
                Text       = message ?? string.Empty,
                Type       = type,
                From       = "{0}.{1}".Args(this.GetType().Name, from),
                Exception  = error,
                Parameters = parameters
            };

            if (relatedMessageID.HasValue)
            {
                logMessage.RelatedTo = relatedMessageID.Value;
            }

            App.Log.Write(logMessage);

            return(logMessage.Guid);
        }
Esempio n. 2
0
        public void LogSecurityMessage(SecurityLogAction action, Log.Message msg, IIdentityDescriptor identity = null)
        {
            if ((SecurityLogMask & action.ToMask()) == 0)
            {
                return;
            }
            if (msg == null)
            {
                return;
            }
            if (SecurityLogLevel > msg.Type)
            {
                return;
            }
            if (msg.ArchiveDimensions.IsNullOrWhiteSpace())
            {
                if (identity == null)
                {
                    identity = ExecutionContext.Session.User;
                }

                msg.ArchiveDimensions = GetUserLogArchiveDimensions(identity).ToLaconicString();
            }

            logSecurityMessage(msg);
        }
Esempio n. 3
0
        private void onLogMsgReceived(object sender, Log.Message e)
        {
            if (!chkDebug.Checked)
            {
                return;
            }

            string msg = $"{e.stamp.ToString("HH:mm:ss.fffff")}] {e.content} :: {sender.ToString()}";

            if (suspendedLog)
            {
                logmsg.Add(msg);
                return;
            }

            uiAction(() =>
            {
                lock (sync)
                {
                    if (listBoxDebug.Items.Count < MAX_DBG_RECORDS)
                    {
                        if (logmsg.Count > 0)
                        {
                            listBoxDebug.Items.AddRange(logmsg.ToArray());
                            logmsg.Clear();
                        }
                        listBoxDebug.Items.Add(msg);
                        listBoxDebug.TopIndex = listBoxDebug.Items.Count - 1;
                        return;
                    }

                    // the RemoveAt() is much more expensive than [Copy + Clear + AddRange] because of logic for moving elements to removed index.
                    // But unfortunately we can't access to array of ListBox elements,
                    // and we can't copy starting with specific index like for Array.Copy ...seriously, who designed this component >(
                    // well, like this:
                    object[] origin = new object[MAX_DBG_RECORDS];
                    listBoxDebug.Items.CopyTo(origin, Math.Max(0, listBoxDebug.Items.Count - MAX_DBG_RECORDS));

                    // then finally:
                    int maxdel    = (int)(MAX_DBG_RECORDS * 0.75);
                    object[] dest = new object[MAX_DBG_RECORDS - maxdel];
                    Array.Copy(origin, maxdel, dest, 0, dest.Length);

                    listBoxDebug.SuspendLayout();
                    listBoxDebug.Items.Clear();
                    listBoxDebug.Items.AddRange(dest);
                    listBoxDebug.ResumeLayout();
                }
            });
        }
Esempio n. 4
0
        void Message(Log.Message message)
        {
            if (log.Count > 9)
            {
                log.RemoveAt(0);
            }
            log.Add(message.text);

            //switch (message.type)
            //{
            //    case Log.MessageType.Info: Debug.Log(message.text); break;
            //    case Log.MessageType.Warning: Debug.LogWarning(message.text); break;
            //    case Log.MessageType.Error: Debug.LogError(message.text); break;
            //}
        }
Esempio n. 5
0
        /// <summary>
        /// Writes a log message for this component; returns the new log msg GDID for correlation, or GDID.Empty if no message was logged.
        /// The file/src are only used if `from` is null/blank
        /// </summary>
        protected internal virtual Guid WriteLog(Log.MessageType type,
                                                 string from,
                                                 string text,
                                                 Exception error = null,
                                                 Guid?related    = null,
                                                 string pars     = null,
                                                 [System.Runtime.CompilerServices.CallerFilePath] string file = null,
                                                 [System.Runtime.CompilerServices.CallerLineNumber] int src   = 0)
        {
            if (type < ComponentEffectiveLogLevel)
            {
                return(Guid.Empty);
            }

            if (from.IsNullOrWhiteSpace())
            {
                from = "{0}:{1}".Args(file.IsNotNullOrWhiteSpace() ? System.IO.Path.GetFileName(file) : "?", src);
            }

            var msg = new Log.Message
            {
                App        = App.AppId,
                Topic      = ComponentLogTopic,
                From       = ComponentLogFromPrefix + from,
                Type       = type,
                Text       = text,
                Exception  = error,
                Parameters = pars,
                Source     = src
            };

            msg.InitDefaultFields(App);

            if (related.HasValue)
            {
                msg.RelatedTo = related.Value;
            }

            App.Log.Write(msg);

            return(msg.Guid);
        }
Esempio n. 6
0
        private static void OnLog(Log.Message message)
        {
            switch (message.severity)
            {
            case Log.Severity.INF:
                Debug.Log(message.ToString(false));
                break;

            case Log.Severity.WAR:
                Debug.LogWarning(message.ToString(false));
                break;

            case Log.Severity.ERR:
                Debug.LogError(message.ToString(false));
                break;

            case Log.Severity.ASS:
                Debug.Assert(false, message.ToString(false));
                Debug.Break();
                break;
            }
        }
Esempio n. 7
0
        public void LogSecurityMessage(Log.Message msg, User user = null)
        {
            if ((LogMask & SecurityLogMask.Custom) == 0)
            {
                return;
            }
            if (msg == null)
            {
                return;
            }
            if (msg.ArchiveDimensions.IsNullOrWhiteSpace())
            {
                if (user == null)
                {
                    user = ExecutionContext.Session.User;
                }

                msg.ArchiveDimensions = GetUserLogArchiveDimensions(user).ToLaconicString();
            }

            logSecurityMessage(msg);
        }
Esempio n. 8
0
 private void logSecurityMessage(Log.Message msg)
 {
     msg.Channel = CoreConsts.LOG_CHANNEL_SECURITY;
     msg.From    = "{0}.{1}".Args(GetType().Name, msg.From);
     App.Log.Write(msg);
 }
Esempio n. 9
0
 public void LogSecurityMessage(SecurityLogAction action, Log.Message msg, IIdentityDescriptor identity = null)
 {
 }
Esempio n. 10
0
 public void LogSecurityMessage(Log.Message msg, User user = null)
 {
 }
Esempio n. 11
0
 private void logSecurityMessage(Log.Message msg)
 {
     msg.From = "{0}.{1}".Args(GetType().Name, msg.From);
     App.Log.Write(msg);
 }
Esempio n. 12
0
 /// <summary>
 /// Outputs log message to application log
 /// </summary>
 public void Log(Log.Message message)
 {
     App.Log.Write(message);
 }