An individual log message.
        public FilterEditorDialog(LogMessage message, LogMessageFilter filter)
        {
            if (message == null)
                throw new ArgumentNullException(nameof(message));
            if (filter == null)
                throw new ArgumentNullException(nameof(filter));

            m_sampleMessage = message;
            m_filter = new LogMessageFilter();
            m_filter.FilterLevel = filter.FilterLevel;
            m_filter.TimeFilter = filter.TimeFilter ?? new TimestampMatching(TimestampMatchingMode.Inside, message.UtcTime.AddMinutes(-1), message.UtcTime.AddMinutes(1));
            m_filter.Classification = filter.Classification ?? new EnumMatchingFlags(EnumMatchingFlagsMode.Any, 1 << (int)message.Classification, message.Classification.ToString());
            m_filter.Level = filter.Level ?? new EnumMatchingFlags(EnumMatchingFlagsMode.Any, 1 << (int)message.Level, message.Level.ToString());
            m_filter.Flags = filter.Flags ?? new EnumMatchingFlags(EnumMatchingFlagsMode.All, (int)message.Flags, message.Flags.ToString());
            m_filter.Assembly = filter.Assembly ?? new StringMatching(StringMatchingMode.Exact, message.AssemblyName);
            m_filter.Type = filter.Type ?? new StringMatching(StringMatchingMode.Exact, message.TypeName);
            m_filter.RelatedType = filter.RelatedType ?? new StringMatching(StringMatchingMode.Exact, message.TypeName);
            m_filter.StackDetails = filter.StackDetails ?? new StackDetailsMatching();
            m_filter.StackTraceDetails = filter.StackTraceDetails ?? new StackTraceMatching();
            m_filter.EventName = filter.EventName ?? new StringMatching(StringMatchingMode.Exact, message.EventName);
            m_filter.MessageText = filter.MessageText ?? new StringMatching(StringMatchingMode.Exact, message.Message);
            m_filter.DetailsText = filter.DetailsText ?? new StringMatching(StringMatchingMode.Exact, message.Details);
            m_filter.ExceptionText = filter.ExceptionText ?? new StringMatching(StringMatchingMode.Exact, message.ExceptionString);

            InitializeComponent();

            chkTime.Checked = filter.TimeFilter != null;
            chkClass.Checked = filter.Classification != null;
            chkLevel.Checked = filter.Level != null;
            chkFlags.Checked = filter.Flags != null;
            chkAssembly.Checked = filter.Assembly != null;
            chkType.Checked = filter.Type != null;
            chkRelatedType.Checked = filter.RelatedType != null;
            chkStackDetails.Checked = filter.StackDetails != null;
            chkStackTrace.Checked = filter.StackTraceDetails != null;
            chkEventName.Checked = filter.EventName != null;
            chkMessage.Checked = filter.MessageText != null;
            chkDetails.Checked = filter.DetailsText != null;
            chkException.Checked = filter.ExceptionText != null;

            lblTime.Text = m_filter.TimeFilter.ToString();
            lblClass.Text = m_filter.Classification.ToString();
            lblLevel.Text = m_filter.Level.ToString();
            lblFlags.Text = m_filter.Flags.ToString();
            lblAssembly.Text = m_filter.Assembly.ToString();
            lblType.Text = m_filter.Type.ToString();
            lblRelatedType.Text = m_filter.RelatedType.ToString();
            lblStackDetails.Text = m_filter.StackDetails.ToString();
            lblStackTrace.Text = m_filter.StackTraceDetails.ToString();
            lblEventName.Text = m_filter.EventName.ToString();
            lblMessage.Text = m_filter.MessageText.ToString();
            lblDetails.Text = m_filter.DetailsText.ToString();
            lblException.Text = m_filter.ExceptionText.ToString();

            cmbVerbose.SelectedIndex = (int)m_filter.FilterLevel;
            chkMessage.Checked = filter.MessageText != null;
            chkMessage.Tag = filter.MessageText ?? new StringMatching(StringMatchingMode.Exact, message.Message);
        }
        /// <summary>
        /// Reads all log messages from the supplied file.
        /// </summary>
        public static void Compact(ICollection<string> inputFileNames, string outputFileName)
        {
            LogCollection logs = new LogCollection();

            foreach (var file in inputFileNames)
            {
                using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    if (stream.ReadBoolean())
                    {
                        //Wrong File Version
                        break;
                    }
                    if (stream.ReadNextByte() != 1)
                    {
                        //Wrong File Version
                        break;
                    }
                    using (var zipStream = new DeflateStream(stream, CompressionMode.Decompress, true))
                    using (var bs = new BufferedStream(zipStream, 8192))
                    {
                        while (bs.ReadBoolean())
                        {
                            var message = new LogMessage(bs);
                            logs.Pass1(message);
                        }
                    }
                }
            }

            logs.Compact();
            foreach (var file in inputFileNames)
            {
                using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    if (stream.ReadBoolean())
                    {
                        //Wrong File Version
                        break;
                    }
                    if (stream.ReadNextByte() != 1)
                    {
                        //Wrong File Version
                        break;
                    }
                    using (var zipStream = new DeflateStream(stream, CompressionMode.Decompress, true))
                    using (var bs = new BufferedStream(zipStream, 8192))
                    {
                        while (bs.ReadBoolean())
                        {
                            var message = new LogMessage(bs);
                            logs.Pass2(message);
                        }
                    }
                }
            }
            logs.Save(outputFileName);
        }
        /// <summary>
        /// Reads all log messages from the supplied file.
        /// </summary>
        public static List<LogMessage> Read(string logFileName)
        {
            List<LogMessage> lst = new List<LogMessage>();
            FilePath.ValidatePathName(logFileName);
            using (var stream = new FileStream(logFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete))
            {
                try
                {
                    LogMessageSaveHelper helper;
                    int version = stream.ReadInt32();
                    switch (version)
                    {
                        case 282497:
                            helper = LogMessageSaveHelper.Create(); //VersionNumber: Compressed. With LogSaveHelper
                            break;
                        default:
                            throw new VersionNotFoundException();
                    }

                    using (var zipStream = new DeflateStream(stream, CompressionMode.Decompress, true))
                    using (var bs = new BufferedStream(zipStream))
                    {
                        while (bs.ReadBoolean())
                        {
                            var message = new LogMessage(bs, helper);
                            lst.Add(message);
                        }
                        bs.Dispose();
                    }
                }
                catch (EndOfStreamException)
                {

                }
                catch (ZlibException)
                {

                }

            }
            return lst;
        }
            public void Assign(LogMessage message, int keepWeight)
            {
                if (Classification != message.Classification || Level != message.Level || UtcDateTime != message.UtcTime)
                    throw new Exception("Parsing Exception");

                if (KeepWeighting >= keepWeight)
                {
                    Message = message;
                }
            }
 public MessageData(LogMessage message)
 {
     Classification = message.Classification;
     Level = message.Level;
     KeepWeighting = 0;
     UtcDateTime = message.UtcTime;
     message = null;
 }
 public void Pass2(LogMessage message)
 {
     AllMessages[m_index].Assign(message, KeepWeight);
     m_index++;
 }
 public bool IsMatch(LogMessage log)
 {
     if (TimeFilter != null)
     {
         if (!TimeFilter.IsMatch(log.UtcTime))
             return false;
     }
     if (Classification != null)
     {
         if (!Classification.IsMatch(1 << (int)log.Classification))
             return false;
     }
     if (Level != null)
     {
         if (!Level.IsMatch(1 << (int)log.Level))
             return false;
     }
     if (Flags != null)
     {
         if (!Flags.IsMatch((int)log.Flags))
             return false;
     }
     if (Assembly != null)
     {
         if (!Assembly.IsMatch(log.AssemblyName))
             return false;
     }
     if (Type != null)
     {
         if (!Type.IsMatch(log.TypeName))
             return false;
     }
     if (RelatedType != null)
     {
         if (!MatchRelatedType(log))
             return false;
     }
     if (StackDetails != null)
     {
         if (!StackDetails.IsMatch(log))
             return false;
     }
     if (StackTraceDetails != null)
     {
         if (!StackTraceDetails.IsMatch(log))
             return false;
     }
     if (EventName != null)
     {
         if (!EventName.IsMatch(log.EventName))
             return false;
     }
     if (MessageText != null)
     {
         if (!MessageText.IsMatch(log.Message))
             return false;
     }
     if (DetailsText != null)
     {
         if (!DetailsText.IsMatch(log.Details))
             return false;
     }
     if (ExceptionText != null)
     {
         if (!ExceptionText.IsMatch(log.ExceptionString))
             return false;
     }
     return true;
 }
 private void SubscriberNewLogMessage(LogMessage logMessage)
 {
     lock (m_syncRoot)
     {
         if (m_path == null)
         {
             LogMessage message;
             if (m_messageQueue.Count >= m_maxQueue)
                 m_messageQueue.TryDequeue(out message);
             m_messageQueue.Enqueue(logMessage);
         }
         else
         {
             m_messageQueue.Enqueue(logMessage);
             m_flushTask.Start(1000);
         }
     }
 }
Esempio n. 9
0
 public TypeMenu(List<LogMessage> selectedLogMessages)
 {
     m_log = selectedLogMessages.First();
 }
        /// <summary>
        /// Assigns the supplied message to this subscriber.
        /// </summary>
        /// <param name="log">the message</param>
        public void RaiseLogMessages(LogMessage log)
        {
            if (m_disposed)
                return;

            lock (m_syncRoot)
            {
                if (m_disposed)
                    return;

                if (m_allSubscriptions == null || m_allSubscriptions.Count == 0)
                    return;

                OnLog(log);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Writes the specified log to the file
        /// </summary>
        /// <param name="log"></param>
        /// <param name="autoFlush"></param>
        public void Write(LogMessage log, bool autoFlush = true)
        {
            try
            {
                m_tmpStream.Position = 0;
                m_tmpStream.Write(true);
                log.Save(m_tmpStream, m_saveHelper);
                long length = m_tmpStream.Position;
                m_tmpStream.Position = 0;
                m_tmpStream.CopyTo(m_zipStream, length, m_tmpBuffer);

                if (log.Level >= MessageLevel.Info && autoFlush)
                {
                    m_zipStream.Flush();
                }

                m_logCount++;
            }
            catch (Exception)
            {
                throw;
            }
        }
 public bool IsMatch(LogMessage log)
 {
     return true;
 }
 private void m_logSubscriber_Log(LogMessage logMessage)
 {
     switch (logMessage.Level)
     {
         case MessageLevel.Critical:
         case MessageLevel.Error:
             ServiceHelper?.ErrorLogger?.Log(logMessage.Exception ?? new InvalidOperationException(logMessage.GetMessage()));
             break;
         case MessageLevel.Warning:
             DisplayStatusMessage($"[SnapEngine] WARNING: {logMessage.Message}", UpdateType.Warning, false);
             break;
         case MessageLevel.Debug:
             break;
         default:
             DisplayStatusMessage($"[SnapEngine] {logMessage.Message}", UpdateType.Information, false);
             break;
     }
 }
        /// <summary>
        /// Raises a log message with the provided data.
        /// </summary>
        /// <param name="overriddenAttributes">attributes to use with this message</param>
        /// <param name="message"></param>
        /// <param name="details">A long text field with the details of the message.</param>
        /// <param name="exception">An exception object if one is provided.</param>
        /// <param name="initialStackMessage"></param>
        /// <param name="initialStackTrace"></param>
        public void Publish(LogMessageAttributes? overriddenAttributes, string message, string details, Exception exception, LogStackMessages initialStackMessage, LogStackTrace initialStackTrace)
        {
            if (Logger.ShouldSuppressLogMessages)
                return;

            LogMessageAttributes attributes = overriddenAttributes ?? m_attributes;

            if (!m_publisher.HasSubscribers(attributes))
                return;

            if (message == null)
                message = string.Empty;
            if (details == null)
                details = string.Empty;

            var suppressionFlags = m_supressionEngine.IncrementPublishCount();
            if (suppressionFlags != MessageSuppression.None)
            {
                m_messagesSuppressed++;

                if (ShouldRaiseMessageSupressionNotifications && m_suppressionMessageNextPublishTime <= ShortTime.Now)
                {
                    m_suppressionMessageNextPublishTime = ShortTime.Now.AddSeconds(10);
                    MessageSuppressionIndication.Publish($"Message Suppression Is Occurring To: '{ m_owner.TypeData.TypeName }' {m_messagesSuppressed.ToString()} total messages have been suppressed.", m_owner.ToString());
                }

                attributes += suppressionFlags;
                if (!m_publisher.HasSubscribers(attributes))
                    return;
            }

            LogStackMessages currentStackMessages = Logger.GetStackMessages();
            LogStackTrace currentStackTrace = LogStackTrace.Empty;
            if (m_stackTraceDepth > 0)
            {
                currentStackTrace = new LogStackTrace(true, 2, m_stackTraceDepth);
            }
            else if (exception != null || attributes.Level >= MessageLevel.Error)
            {
                currentStackTrace = new LogStackTrace(true, 2, 10);
            }

            var logMessage = new LogMessage(m_owner, initialStackMessage, initialStackTrace, currentStackMessages, currentStackTrace, attributes, message, details, exception);
            m_logger.OnNewMessage(logMessage, m_publisher);
        }
 private void SubscriberNewLogMessage(LogMessage logMessage)
 {
     string text = "---------------------------------------------------------" + Environment.NewLine + logMessage.GetMessage() + Environment.NewLine + "---------------------------------------------------------";
     System.Console.WriteLine(text);
 }
 private bool MatchRelatedType(LogMessage log)
 {
     if (RelatedType.IsMatch(log.TypeName))
         return true;
     foreach (var item in log.RelatedTypes)
     {
         if (RelatedType.IsMatch(item))
             return true;
     }
     return false;
 }
 void subscriber_Log(LogMessage logMessage)
 {
     Console.WriteLine(logMessage.GetMessage());
 }
Esempio n. 18
0
 /// <summary>
 /// Handles the routing of messages through the logging system.
 /// </summary>
 /// <param name="message">the message to route</param>
 /// <param name="publisher">the publisher that is originating this message.</param>
 public void OnNewMessage(LogMessage message, LogPublisherInternal publisher)
 {
     m_messages.Enqueue(Tuple.Create(message, publisher));
     m_routingTask.Start(50); //Allow a 50ms delay for multiple logs to queue if in a burst period.
 }
 /// <summary>
 /// Raises the <see cref="NewLogMessage"/> event.
 /// </summary>
 /// <param name="logMessage">the message to raise.</param>
 private void OnLog(LogMessage logMessage)
 {
     if (logMessage == null)
         return;
     try
     {
         using (Logger.SuppressFirstChanceExceptionLogMessages())
         {
             NewLogMessage?.Invoke(logMessage);
         }
     }
     catch (Exception)
     {
         //Swallow this exception
         //This is because if a subscriber throws an exception, creating a new log
         //might cause an infinite loop.
     }
 }
 public void Pass1(LogMessage message)
 {
     MessageByOwner m;
     if (!m_owners.TryGetValue(message.EventPublisherDetails, out m))
     {
         m = new MessageByOwner(message.EventPublisherDetails);
         m_owners.Add(message.EventPublisherDetails, m);
     }
     m.Pass1(message);
 }
 public void Pass2(LogMessage message)
 {
     m_owners[message.EventPublisherDetails].Pass2(message);
 }
 public void Pass1(LogMessage message)
 {
     AllMessages.Add(new MessageData(message));
 }
        private void WriteLogMessage(LogMessage log)
        {
            //Rollover a file if over 500KB in size, over 50000 records, or older than 12 hours.
            //Ideally, 500KB will always come first.
            if (m_writer != null && (m_writer.LogSize > 500 * 1024 || m_writer.LogCount >= 50000 || m_fileAge.Elapsed.TotalHours > 12))
            {
                string fileName = m_writer.FileName;
                m_writer.Dispose();
                m_writer = null;
                OnNewFileComplete(fileName);
            }

            if (m_writer == null)
            {
                m_fileAge.Restart();
                try
                {
                    if (m_maxFileCount > 0)
                    {
                        string[] files = Directory.GetFiles(m_path, "*.logz");
                        if (files.Length > m_maxFileCount)
                        {
                            Array.Sort(files);

                            for (int x = 0; x < files.Length - m_maxFileCount; x++)
                            {
                                File.Delete(files[x]);
                            }
                        }
                    }
                }
                catch (Exception)
                {
                }
                string file = $"{DateTime.UtcNow.ToString("yyyyMMdd-HHmmss-ffffff")} - {m_processName} - {m_fileSequenceNumber}.logz";
                m_fileSequenceNumber++;
                var fileName = Path.Combine(m_path, file);
                m_writer = new LogFileWriter(fileName);
            }

            m_writer.Write(log, false);
        }
Esempio n. 24
0
 public ExceptionMenu(List<LogMessage> selectedLogMessages)
 {
     m_log = selectedLogMessages.First();
 }