public StackDetailsFilter(LogStackMessages details) { InitializeComponent(); for (int x = 0; x < details.Count; x++) { checkedListBox1.Items.Add(new KVP(details[x])); } }
private void BtnOK_Click(object sender, EventArgs e) { if (checkedListBox1.CheckedItems.Count == 0) { MessageBox.Show("Select an item"); return; } SelectedItems = new LogStackMessages(checkedListBox1.CheckedItems.Cast <KVP>().Select(x => x.Values).ToList()); DialogResult = DialogResult.OK; }
/// <summary> /// Creates a <see cref="EventTimer"/> /// </summary> /// <param name="period"></param> /// <param name="dayOffset"></param> private EventTimer(TimeSpan period, TimeSpan dayOffset) : base(MessageClass.Component) { m_stopping = false; m_syncRoot = new object(); m_period = period; m_dayOffset = dayOffset; m_message = LogStackMessages.Empty.Union("Event Timer Details", string.Format("EventTimer: {0} in {1}", m_period, m_dayOffset)); Log.InitialStackMessages.Union("Event Timer Details", string.Format("EventTimer: {0} in {1}", m_period, m_dayOffset)); }
/// <summary> /// Listen for a socket connection /// </summary> public CtpServer(IPEndPoint listenEndpoint, IServerAuthentication config) { m_config = config; m_listenEndpoint = listenEndpoint ?? throw new ArgumentNullException(nameof(listenEndpoint)); m_onAccept = OnAccept; var logMessages = new LogStackMessages("Listen Port", listenEndpoint.ToString()); using (Logger.AppendStackMessages(logMessages)) Log = Logger.CreatePublisher(typeof(CtpServer), MessageClass.Framework); }
private void BtnOK_Click(object sender, EventArgs e) { if (checkedListBox1.CheckedItems.Count == 0) { MessageBox.Show("Select an item"); return; } SelectedItems = new LogStackMessages(checkedListBox1.CheckedItems.Cast<KVP>().Select(x=>x.Values).ToList()); DialogResult = DialogResult.OK; }
public LogStackMessages GetStackMessages() { if (m_stackMessageCache == null) { if (m_threadStackDetails.Count == 0) { m_stackMessageCache = LogStackMessages.Empty; } else { m_stackMessageCache = new LogStackMessages(m_threadStackDetails); } } return m_stackMessageCache; }
/// <summary> /// Creates a log message /// </summary> internal LogMessage(LogEventPublisherDetails eventPublisherDetails, LogStackMessages initialStackMessages, LogStackTrace initialStackTrace, LogStackMessages currentStackMessages, LogStackTrace currentStackTrace, LogMessageAttributes flags, string message, string details, Exception exception) { if (eventPublisherDetails == null) throw new ArgumentNullException(nameof(eventPublisherDetails)); if (exception != null) { ExceptionString = exception.ToString(); } else { ExceptionString = string.Empty; } EventPublisherDetails = eventPublisherDetails; InitialStackMessages = initialStackMessages ?? LogStackMessages.Empty; InitialStackTrace = initialStackTrace ?? LogStackTrace.Empty; CurrentStackMessages = currentStackMessages ?? LogStackMessages.Empty; CurrentStackTrace = currentStackTrace ?? LogStackTrace.Empty; UtcTime = DateTime.UtcNow; LogMessageAttributes = flags; Message = message ?? string.Empty; Details = details ?? string.Empty; Exception = exception; ManagedThreadID = Thread.CurrentThread.ManagedThreadId; PreviousFirstChanceExceptionSequenceNumber = Logger.PreviousFirstChanceExceptionSequenceNumber; }
/// <summary> /// Loads a log messages from the supplied stream /// </summary> /// <param name="stream">the stream to load the log message from.</param> /// <param name="saveHelper">A save helper that will condense objects</param> internal LogMessage(Stream stream, LogMessageSaveHelper saveHelper = null) { if (saveHelper == null) saveHelper = LogMessageSaveHelper.Create(true); byte version = stream.ReadNextByte(); switch (version) { case 1: EventPublisherDetails = saveHelper.LoadEventPublisherDetails(stream); InitialStackMessages = saveHelper.LoadStackMessages(stream); InitialStackTrace = saveHelper.LoadStackTrace(stream); CurrentStackMessages = saveHelper.LoadStackMessages(stream); CurrentStackTrace = saveHelper.LoadStackTrace(stream); UtcTime = stream.ReadDateTime(); LogMessageAttributes = new LogMessageAttributes(stream); Message = stream.ReadString(); Details = stream.ReadString(); Exception = null; ExceptionString = stream.ReadString(); ManagedThreadID = -1; PreviousFirstChanceExceptionSequenceNumber = -1; break; case 2: EventPublisherDetails = saveHelper.LoadEventPublisherDetails(stream); InitialStackMessages = saveHelper.LoadStackMessages(stream); InitialStackTrace = saveHelper.LoadStackTrace(stream); CurrentStackMessages = saveHelper.LoadStackMessages(stream); CurrentStackTrace = saveHelper.LoadStackTrace(stream); UtcTime = stream.ReadDateTime(); LogMessageAttributes = new LogMessageAttributes(stream); Message = stream.ReadString(); Details = stream.ReadString(); Exception = null; ExceptionString = stream.ReadString(); ManagedThreadID = stream.ReadInt32(); PreviousFirstChanceExceptionSequenceNumber = -1; break; case 3: EventPublisherDetails = saveHelper.LoadEventPublisherDetails(stream); InitialStackMessages = saveHelper.LoadStackMessages(stream); InitialStackTrace = saveHelper.LoadStackTrace(stream); CurrentStackMessages = saveHelper.LoadStackMessages(stream); CurrentStackTrace = saveHelper.LoadStackTrace(stream); UtcTime = stream.ReadDateTime(); LogMessageAttributes = new LogMessageAttributes(stream); Message = saveHelper.LoadString(stream); Details = saveHelper.LoadString(stream); Exception = null; ExceptionString = saveHelper.LoadString(stream); ManagedThreadID = stream.ReadInt32(); PreviousFirstChanceExceptionSequenceNumber = -1; break; case 4: EventPublisherDetails = saveHelper.LoadEventPublisherDetails(stream); InitialStackMessages = saveHelper.LoadStackMessages(stream); InitialStackTrace = saveHelper.LoadStackTrace(stream); CurrentStackMessages = saveHelper.LoadStackMessages(stream); CurrentStackTrace = saveHelper.LoadStackTrace(stream); UtcTime = stream.ReadDateTime(); LogMessageAttributes = new LogMessageAttributes(stream); Message = saveHelper.LoadString(stream); Details = saveHelper.LoadString(stream); Exception = null; ExceptionString = saveHelper.LoadString(stream); ManagedThreadID = stream.ReadInt32(); PreviousFirstChanceExceptionSequenceNumber = stream.ReadInt32(); break; default: throw new VersionNotFoundException(); } }
internal LogPublisher(LoggerInternal logger, LogPublisherInternal publisherInstance, MessageClass classification) { m_logger = logger; m_publisherInstance = publisherInstance; m_classification = classification; InitialStackMessages = Logger.GetStackMessages(); InitialStackTrace = new LogStackTrace(true, 1, 10); MaxDistinctEventPublisherCount = 20; m_lookupEventPublishers = new ConcurrentDictionary<Tuple<LogMessageAttributes, string>, LogEventPublisherInternal>(); }
/// <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); }
public StackDisposal AppendStackMessages(LogStackMessages messages) { m_stackMessageCache = null; m_threadStackDetails.Add(messages); int depth = m_threadStackDetails.Count; if (depth >= s_stackDisposalStackMessages.Length) { GrowStackDisposal(depth); } return s_stackDisposalStackMessages[depth]; }
/// <summary> /// Temporarily appends data to the thread's stack so the data can be propagated to any messages generated on this thread. /// Be sure to call Dispose on the returned object to remove this from the stack. /// </summary> /// <param name="messages"></param> /// <returns></returns> public static IDisposable AppendStackMessages(LogStackMessages messages) { return ThreadLocalThreadStack.Value.AppendStackMessages(messages); }
public void RemoveStackMessage(int depth) { while (m_threadStackDetails.Count >= depth) { m_threadStackDetails.RemoveAt(m_threadStackDetails.Count - 1); } m_stackMessageCache = null; }
public LogStackMessages LoadStackMessages(Stream stream) { byte version = stream.ReadNextByte(); switch (version) { case 0: return LogStackMessages.Empty; case 1: return new LogStackMessages(stream); case 2: { if (m_isSimple) throw new Exception("Cannot load without a LogMessageSaveHelper"); int id = stream.ReadInt32(); return m_stackMessagesLoadLookup[id]; } case 3: { if (m_isSimple) throw new Exception("Cannot load without a LogMessageSaveHelper"); int id = stream.ReadInt32(); var messages = new LogStackMessages(stream); m_stackMessagesLoadLookup.Add(messages); return messages; } case 4: { if (m_isSimple) throw new Exception("Cannot load without a LogMessageSaveHelper"); var messages = new LogStackMessages(stream); m_stackMessagesLoadLookup.Add(messages); return messages; } default: throw new VersionNotFoundException(); } }
public void SaveStackMessages(Stream stream, LogStackMessages message) { if (message == null) throw new ArgumentNullException(nameof(message)); if (ReferenceEquals(message, LogStackMessages.Empty)) { stream.Write((byte)0); } else if (m_isSimple) { stream.Write((byte)1); message.Save(stream); } else { int lookupId; if (m_stackMessagesSaveLookup.TryGetValue(message, out lookupId)) { stream.Write((byte)2); stream.Write(lookupId); } else { lookupId = m_stackMessagesSaveLookup.Count; stream.Write((byte)4); message.Save(stream); m_stackMessagesSaveLookup.Add(message, lookupId); } } }