Example #1
0
        /// <summary>
        /// Computes an MD5 hash code for the log entry
        /// </summary>
        /// <param name="extension">The extended entry information (or <c>null</c>).</param>
        /// <param name="entryType">The log entry type.</param>
        /// <param name="message">The log message (or <c>null</c>).</param>
        /// <param name="e">The logged exception (or <c>null</c>).</param>
        /// <returns>The computed hash.</returns>
        private static MD5Key ComputeMD5Hash(ISysLogEntryExtension extension, SysLogEntryType entryType, string message, Exception e)
        {
            StringBuilder sb = new StringBuilder(1024);

            if (extension != null)
            {
                sb.Append(extension.Format());
            }

            sb.Append('\t');

            sb.Append(entryType.ToString());
            sb.Append('\t');

            if (message != null)
            {
                sb.Append(message);
            }

            sb.Append('\t');

            if (e != null)
            {
                sb.Append(e.GetType().FullName);
                sb.Append('\t');
                sb.Append(e.Message);
                sb.Append('\t');
                sb.Append(e.StackTrace.ToString());
            }

            return(new MD5Key(MD5Hasher.Compute(sb.ToString())));
        }
Example #2
0
 /// <summary>
 /// Constructs a log entry.
 /// </summary>
 /// <param name="type">The entry type.</param>
 /// <param name="message">The message.</param>
 /// <param name="extension">The extended log information (or <c>null</c>).</param>
 public SysLogEntry(ISysLogEntryExtension extension, SysLogEntryType type, string message)
 {
     this.Time      = DateTime.UtcNow;
     this.Type      = type;
     this.Message   = message;
     this.Extension = extension;
 }
Example #3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="extension">Extended log entry information (or <c>null</c>).</param>
 /// <param name="entryType">Indicates the log entry type.</param>
 /// <param name="message">The log message (or <c>null</c>).</param>
 /// <param name="e">The exception (or <c>null</c>).</param>
 public CachedEntry(ISysLogEntryExtension extension, SysLogEntryType entryType, string message, Exception e)
 {
     this.EntryType    = entryType;
     this.Extension    = extension;
     this.Message      = message;
     this.Exception    = e;
     this.FirstTime    =
         this.LastTime = DateTime.UtcNow;
     this.TTD          = SysTime.Now + cacheTime;
     this.Count        = 1;
 }
Example #4
0
        /// <summary>
        /// Constucts an exception based log entry.
        /// </summary>
        /// <param name="extension">The extended log information (or <c>null</c>).</param>
        /// <param name="e">The exception.</param>
        /// <param name="message">The message.</param>
        public SysLogEntry(ISysLogEntryExtension extension, Exception e, string message)
        {
            TargetInvocationException eInvoke;

            eInvoke = e as TargetInvocationException;
            if (eInvoke != null)
            {
                e = eInvoke.InnerException;
            }

            this.Time      = DateTime.UtcNow;
            this.Type      = SysLogEntryType.Exception;
            this.Exception = e;
            this.Message   = message;
            this.Extension = extension;
        }
Example #5
0
        //---------------------------------------------------------------------
        // Static members

        /// <summary>
        /// Maps a LillTek log entry type into the corresponding FreeSWITCH log level.
        /// </summary>
        /// <param name="entryType">The LillTek log level.</param>
        /// <returns>The corresponding FreeSWITCH log level.</returns>
        private static SwitchLogLevel MapLogLevel(SysLogEntryType entryType)
        {
            switch (entryType)
            {
            case SysLogEntryType.Information:       return(SwitchLogLevel.Info);

            case SysLogEntryType.Warning:           return(SwitchLogLevel.Warning);

            case SysLogEntryType.Error:             return(SwitchLogLevel.Error);

            case SysLogEntryType.SecuritySuccess:   return(SwitchLogLevel.Notice);

            case SysLogEntryType.SecurityFailure:   return(SwitchLogLevel.Warning);

            case SysLogEntryType.Exception:         return(SwitchLogLevel.Error);

            case SysLogEntryType.Trace:             return(SwitchLogLevel.Debug);

            default:                                return(SwitchLogLevel.Info);
            }
        }
Example #6
0
 /// <summary>
 /// Handles the caching for a log entry.
 /// </summary>
 /// <param name="extension">Extended log entry information or (<c>null</c>).</param>
 /// <param name="entryType">The log entry type.</param>
 /// <param name="message">The log message (or <c>null</c>).</param>
 /// <param name="e">The logged exception (or <c>null</c>).</param>
 /// <returns><c>true</c> if the entry is in the cache and should not be logged.</returns>
 private static bool IsCached(ISysLogEntryExtension extension, SysLogEntryType entryType, string message, Exception e)
 {
     return(false);   // Caching is not implemented for Silverlight
 }
Example #7
0
        /// <summary>
        /// Handles the caching for a log entry.
        /// </summary>
        /// <param name="extension">Extended log entry information or (<c>null</c>).</param>
        /// <param name="entryType">The log entry type.</param>
        /// <param name="message">The log message (or <c>null</c>).</param>
        /// <param name="e">The logged exception (or <c>null</c>).</param>
        /// <returns><c>true</c> if the entry is in the cache and should not be logged.</returns>
        private static bool IsCached(ISysLogEntryExtension extension, SysLogEntryType entryType, string message, Exception e)
        {
            lock (cache)
            {
                if (cacheTime == TimeSpan.Zero)
                {
                    return(false);
                }

                switch (entryType)
                {
                case SysLogEntryType.Trace:

                    if (!SysLog.CacheDebug)
                    {
                        return(false);
                    }

                    break;

                case SysLogEntryType.Error:

                    if (!SysLog.CacheErrors)
                    {
                        return(false);
                    }

                    break;

                case SysLogEntryType.Exception:

                    if (!SysLog.CacheExceptions)
                    {
                        return(false);
                    }

                    break;

                case SysLogEntryType.Information:

                    if (!SysLog.CacheInformation)
                    {
                        return(false);
                    }

                    break;

                case SysLogEntryType.SecurityFailure:
                case SysLogEntryType.SecuritySuccess:

                    if (!SysLog.CacheSecurity)
                    {
                        return(false);
                    }

                    break;

                case SysLogEntryType.Warning:

                    if (!SysLog.CacheWarnings)
                    {
                        return(false);
                    }

                    break;

                default:

                    Debug.WriteLine("Unexpected log entry type.");
                    break;
                }

                MD5Key      key = ComputeMD5Hash(extension, entryType, message, e);
                CachedEntry entry;

                if (cache.TryGetValue(key, out entry))
                {
                    entry.Count++;
                    entry.LastTime = DateTime.UtcNow;
                    return(true);
                }

                entry = new CachedEntry(extension, entryType, message, e);
                cache.Add(key, entry);
                return(false);
            }
        }