/// <summary> /// Filter single item, passing it trough all filters. /// </summary> public bool FilterItem(TracerItem item) { lock (this) { return(FilterItem(_filters, item)); } }
void _tracer_ItemAddedEvent(TracerItemKeeperSink sink, TracerItem item) { if (toolStripButtonAutoUpdate.Checked) {// Only updating on new items added, when auto update is enabled. _itemsModified = true; } }
public override bool FilterItem(TracerItem item) { if (item is EnumTracerItem == false) { return true; } lock (this) { foreach (EnumStruct enumStruct in _filteredOutEnums) { if (((EnumTracerItem)item).EnumType == enumStruct.EnumType) { return false; } } EnumStruct enumStruct2 = GetEnumStruct(_allEnums, ((EnumTracerItem)item).EnumType); if (enumStruct2 != null) { return enumStruct2.Values[((EnumTracerItem)item).ValueIndex]; } else { return true; } } }
public override bool FilterItem(TracerItem item) { if (item is EnumTracerItem == false) { return(true); } lock (this) { foreach (EnumStruct enumStruct in _filteredOutEnums) { if (((EnumTracerItem)item).EnumType == enumStruct.EnumType) { return(false); } } EnumStruct enumStruct2 = GetEnumStruct(_allEnums, ((EnumTracerItem)item).EnumType); if (enumStruct2 != null) { return(enumStruct2.Values[((EnumTracerItem)item).ValueIndex]); } else { return(true); } } }
/// <summary> /// Helper, shows an item to constrol. /// Always call on UI thread. /// </summary> void ShowItem(TracerItem item) { _itemShown = item; if (item == null) { this.toolStripStatusLabelReport.Text = string.Empty; } else { if ((item.FullType & TracerItem.TypeEnum.Error) != 0) { toolStripStatusLabelReport.ForeColor = Color.DarkRed; } else if ((item.FullType & TracerItem.TypeEnum.Warning) != 0) { toolStripStatusLabelReport.ForeColor = Color.DarkBlue; } else { toolStripStatusLabelReport.ForeColor = SystemColors.ControlText; } _lastShow = DateTime.Now; this.toolStripStatusLabelReport.Text = "[" + _pendingMessageItems.Count.ToString() + "] " + item.PrintMessage(); } }
public static bool FilterItem(TracerItem item, string positiveFilterString, string[] negativeFilterStrings) { string message = item.PrintMessage().ToLower(); // Positive filter check. if (string.IsNullOrEmpty(positiveFilterString) == false && message.Contains(positiveFilterString.ToLower()) == false) { return false; } if (negativeFilterStrings != null) { // Negative filter check. foreach (string filter in negativeFilterStrings) { if (string.IsNullOrEmpty(filter) == false && message.Contains(filter.ToLower())) { return false; } } } // Pass. return true; }
public static bool FilterItem(TracerItem item, string positiveFilterString, string[] negativeFilterStrings) { string message = item.PrintMessage().ToLower(); // Positive filter check. if (string.IsNullOrEmpty(positiveFilterString) == false && message.Contains(positiveFilterString.ToLower()) == false) { return(false); } if (negativeFilterStrings != null) { // Negative filter check. foreach (string filter in negativeFilterStrings) { if (string.IsNullOrEmpty(filter) == false && message.Contains(filter.ToLower())) { return(false); } } } // Pass. return(true); }
/// <summary> /// Constructor. /// </summary> public MethodTracerItem(TypeEnum itemType, TracerItem.PriorityEnum priority, string message, MethodBase methodInfo, string threadName, string threadId) : base(itemType, priority, message) { _methodBase = methodInfo; _threadId = threadId; _threadName = threadName; }
/// <summary> /// /// </summary> public override bool FilterItem(TracerItem item) { if (string.IsNullOrEmpty(_positiveFilterString) == false || _negativeFilterStrings != null) { return(FilterItem(item, _positiveFilterString, _negativeFilterStrings)); } return(true); }
/// <summary> /// This is mean to be used with not properly managed code (for ex. Managed C++ wrapper) /// that does not allow for the gathering of baseMethod, thread and assembly information /// with reflection. /// </summary> /// <param name="?"></param> public static void TraceSimple(TracerItem.TypeEnum itemType, string message) { Tracer tracer = _tracer; if (tracer.Enabled && tracer != null) { TracerItem item = new TracerItem(itemType, TracerItem.PriorityEnum.Default, message); tracer.Add(item); } }
void _timer_Tick(object sender, EventArgs e) { if ((_pendingMessageItems.Count > 0 || _itemShown != null) && (DateTime.Now - _lastShow) > _previewStayOnInterval) { if (_itemShown == null) { if (_pendingMessageItems.Count > 0) { TracerItem item = null; lock (this) { item = _pendingMessageItems[0]; _pendingMessageItems.Remove(item); } ShowItem(item); } } else { ShowItem(null); } } if (_itemKeeperSink != null) { string errorsText = string.Empty, warningsText = string.Empty, reportsText = string.Empty; lock (_itemKeeperSink) { if (_itemKeeperSink.ItemsByTypeUnsafe != null) { errorsText = "Errors " + (_itemKeeperSink.ItemsByTypeUnsafe[TracerItem.TypeEnum.Error].Count).ToString(); warningsText = "Warnings " + (_itemKeeperSink.ItemsByTypeUnsafe[TracerItem.TypeEnum.Warning].Count).ToString(); } reportsText = "Reports " + (_itemKeeperSink.FilteredItemsCount).ToString(); } if (toolStripStatusLabelErrorsLink.Text != errorsText) { toolStripStatusLabelErrorsLink.Text = errorsText; } if (toolStripStatusLabelWarningsLink.Text != warningsText) { toolStripStatusLabelWarningsLink.Text = warningsText; } if (toolStripStatusLabelReportsLink.Text != reportsText) { toolStripStatusLabelReportsLink.Text = reportsText; } } }
protected void LoadTracerItem(TracerItem item) { if (item == null) { textBoxSelectedItemMessage.Text = string.Empty; } else { textBoxSelectedItemMessage.Text = item.PrintMessage(); } this.propertyGridItem.SelectedObject = item; }
/// <summary> /// Filter single item, passing it trough all filters. /// Will return true if item is allowed to pass filter. /// </summary> /// <param name="filters"></param> /// <param name="item"></param> public static bool FilterItem(IEnumerable <TracerFilter> filters, TracerItem item) { foreach (TracerFilter filter in filters) { if (filter.FilterItem(item) == false) { return(false); } } return(true); }
/// <summary> /// /// </summary> public virtual bool ReceiveItem(TracerItem item, bool isFilteredOut) { if (_enabled && (isFilteredOut || _processNonFilteredOutItems)) { bool filteredBySink = false; filteredBySink = !Tracer.FilterItem(FiltersArray, item); return(OnReceiveItem(item, isFilteredOut, filteredBySink)); } return(true); }
/// <summary> /// Perform actual item tracing. /// </summary> /// <param name="tracer"></param> /// <param name="itemType"></param> /// <param name="message"></param> public static void DoTrace(Tracer tracer, TracerItem.TypeEnum itemType, TracerItem.PriorityEnum priority, string message) { if (tracer != null && tracer.Enabled) { string threadId = Thread.CurrentThread.ManagedThreadId.ToString(); string threadName = Thread.CurrentThread.Name; MethodBase method = ReflectionHelper.GetExternalCallingMethod(3, OwnerTypes); MethodTracerItem item = new MethodTracerItem(itemType, priority, message, method); tracer.Add(item); } }
public bool GetItemTypeFiltering(TracerItem.TypeEnum itemType) { lock (this) { if (_itemTypes.ContainsKey(itemType)) { return _itemTypes[itemType]; } } SystemMonitor.Warning("Unknown item type introduced."); return false; }
protected override bool OnReceiveItem(TracerItem item, bool isFilteredOutByTracer, bool isFilteredOutBySink) { if (isFilteredOutByTracer) { return(true); } if (_maxItems > 0 && _items.Count > _maxItems) {// Remove the first 10%, only low importance items. lock (this) { _items.RemoveRange(0, (int)((float)_maxItems / 10f)); } // Also update at this moment filtered items. //ReFilterItems(); if (_filteredItems.Count > _maxItems) { lock (this) { _filteredItems.RemoveRange(0, (int)((float)_maxItems / 10f)); } } } lock (this) { _items.Add(item); if (_itemsByType != null) { foreach (TracerItem.TypeEnum type in item.Types) { _itemsByType[type].Add(item); } } if (isFilteredOutBySink == false) { _filteredItems.Add(item); } } if (isFilteredOutBySink == false && ItemAddedEvent != null) { ItemAddedEvent(this, item); } return(true); }
/// <summary> /// Perform filtering of an item. /// </summary> /// <param name="item"></param> /// <returns></returns> public override bool FilterItem(TracerItem item) { lock (this) { foreach (TracerItem.TypeEnum itemType in item.Types) { if (_itemTypes[itemType]) { return(true); } } } return(false); }
void _tracer_ItemAddedEvent(Tracer tracer, TracerItem item) { if ((item.FullType & _filterItemType) != 0) { lock (this) { if (_pendingMessageItems.Count > MaxPendingItems) { _pendingMessageItems.RemoveAt(0); } _pendingMessageItems.Add(item); } } }
/// <summary> /// Perform filtering of an item. /// </summary> /// <param name="item"></param> /// <returns></returns> public override bool FilterItem(TracerItem item) { lock (this) { foreach (TracerItem.TypeEnum itemType in item.Types) { if (_itemTypes[itemType]) { return true; } } } return false; }
private void listViewMain_SelectedIndexChanged(object sender, EventArgs e) { TracerItem item = null; if (_itemKeeperSink != null && listView.SelectedIndices.Count > 0) { int index = listView.SelectedIndices[0]; if (index < listView.VirtualListSize - CleanVirtualItemsCount) { item = _itemKeeperSink.GetFilteredItem(index); } } LoadTracerItem(item); }
/// <summary> /// /// </summary> public override bool FilterItem(TracerItem item) { if (item is MethodTracerItem == false) { return true; } bool updated = false; bool result = false; lock (this) { MethodTracerItem actualItem = (MethodTracerItem)item; if (_assemblies.ContainsKey(actualItem.MethodBase.DeclaringType.Assembly) == false) {// Add assembly. _assemblies.Add(actualItem.MethodBase.DeclaringType.Assembly, new AssemblyTracingInformation()); updated = true; } if (_assemblies[actualItem.MethodBase.DeclaringType.Assembly].Enabled == false) {// Entire assembly stopped. return false; } if (_assemblies[actualItem.MethodBase.DeclaringType.Assembly].Types.ContainsKey(actualItem.MethodBase.DeclaringType) == false) {// Add type. _assemblies[actualItem.MethodBase.DeclaringType.Assembly].Types.Add(actualItem.MethodBase.DeclaringType, true); updated = true; result = true; } else { return _assemblies[actualItem.MethodBase.DeclaringType.Assembly].Types[actualItem.MethodBase.DeclaringType]; } } if (updated) { RaiseFilterUpdatedEvent(); } return result; }
/// <summary> /// /// </summary> public override bool FilterItem(TracerItem item) { if (item is MethodTracerItem == false) { return(true); } bool updated = false; bool result = false; lock (this) { MethodTracerItem actualItem = (MethodTracerItem)item; if (_assemblies.ContainsKey(actualItem.MethodBase.DeclaringType.Assembly) == false) {// Add assembly. _assemblies.Add(actualItem.MethodBase.DeclaringType.Assembly, new AssemblyTracingInformation()); updated = true; } if (_assemblies[actualItem.MethodBase.DeclaringType.Assembly].Enabled == false) {// Entire assembly stopped. return(false); } if (_assemblies[actualItem.MethodBase.DeclaringType.Assembly].Types.ContainsKey(actualItem.MethodBase.DeclaringType) == false) {// Add type. _assemblies[actualItem.MethodBase.DeclaringType.Assembly].Types.Add(actualItem.MethodBase.DeclaringType, true); updated = true; result = true; } else { return(_assemblies[actualItem.MethodBase.DeclaringType.Assembly].Types[actualItem.MethodBase.DeclaringType]); } } if (updated) { RaiseFilterUpdatedEvent(); } return(result); }
/// <summary> /// Add a new tracer item to tracer. /// </summary> public void Add(TracerItem tracerItem) { if (this.Enabled == false) { return; } tracerItem.Index = _totalItemsCount; Interlocked.Increment(ref _totalItemsCount); bool filtered = FilterItem(tracerItem); foreach (ITracerItemSink sink in ItemSinksArray) { sink.ReceiveItem(tracerItem, !filtered); } if (ItemAddedEvent != null) { ItemAddedEvent(this, tracerItem); } }
/// <summary> /// /// </summary> protected override bool OnReceiveItem(TracerItem item, bool isFilteredOutByTracer, bool isFilteredOutBySink) { if (isFilteredOutByTracer) { return(true); } lock (this) { if (LimitItemsSetSize(_items)) { LimitItemsSetSize(_filteredItems); } _items.Add(item); if (isFilteredOutBySink == false) { _filteredItems.Add(item); } if (_itemsByType != null) { foreach (TracerItem.TypeEnum type in item.Types) { LimitItemsSetSize(_itemsByType[type]); _itemsByType[type].Add(item); } } } if (isFilteredOutBySink == false && ItemAddedEvent != null) { ItemAddedEvent(this, item); } return(true); }
/// <summary> /// Add a new tracer item to tracer. /// </summary> public void Add(TracerItem tracerItem) { if (this.Enabled == false) { return; } lock (this) { tracerItem.Index = _totalItemsCount; _totalItemsCount++; bool filtered = FilterItem(tracerItem); foreach (ITracerItemSink sink in _itemSinks) { sink.ReceiveItem(tracerItem, !filtered); } } if (ItemAddedEvent != null) { ItemAddedEvent(this, tracerItem); } }
/// <summary> /// /// </summary> public void SetItemTypesFiltering(TracerItem.TypeEnum[] itemTypes, bool[] filterings) { bool modified = false; lock (this) { for (int i = 0; i < itemTypes.Length; i++) { if (_itemTypes.ContainsKey(itemTypes[i]) && _itemTypes[itemTypes[i]] == filterings[i]) { continue; } modified = true; _itemTypes[itemTypes[i]] = filterings[i]; } } if (modified) { RaiseFilterUpdatedEvent(); } }
/// <summary> /// /// </summary> public static void OperationWarning(string warningMessage, TracerItem.PriorityEnum priority) { TracerHelper.TraceOperationWarning(warningMessage); if (GlobalDiagnosticsMode && priority > TracerItem.PriorityEnum.Medium) { Debug.Fail(warningMessage); } }
/// <summary> /// /// </summary> public static void CheckOperationWarning(bool condition, string message, TracerItem.PriorityEnum priority) { if (condition == false) { OperationWarning(message, priority); } }
/// <summary> /// Override in child class to handle item acqustion. /// </summary> protected abstract bool OnReceiveItem(TracerItem item, bool isFilteredOutByTracer, bool isFilteredOutBySink);
/// <summary> /// /// </summary> public void OperationWarning(string warningMessage, TracerItem.PriorityEnum priority) { if (_enabledOperationWarning) { SystemMonitor.OperationWarning(warningMessage, priority); } }
/// <summary> /// /// </summary> /// <param name="errorMessage"></param> public void OperationError(string errorMessage, TracerItem.PriorityEnum priority) { SystemMonitor.OperationError(errorMessage, priority); }
/// <summary> /// Will return true if item is allowed to pass filter. /// </summary> public abstract bool FilterItem(TracerItem item);
/// <summary> /// Filter single item, passing it trough all filters. /// </summary> public bool FilterItem(TracerItem item) { return(FilterItem(FiltersArray, item)); }
/// <summary> /// Filter single item, passing it trough all filters. /// </summary> public bool FilterItem(TracerItem item) { lock (this) { return FilterItem(_filters, item); } }
/// <summary> /// Filter single item, passing it trough all filters. /// Will return true if item is allowed to pass filter. /// </summary> /// <param name="filters"></param> /// <param name="item"></param> public static bool FilterItem(IEnumerable<TracerFilter> filters, TracerItem item) { foreach (TracerFilter filter in filters) { if (filter.FilterItem(item) == false) { return false; } } return true; }
/// <summary> /// Constructor. /// </summary> public MethodTracerItem(TypeEnum itemType, TracerItem.PriorityEnum priority, string message, MethodBase methodInfo) : base(itemType, priority, message) { _methodBase = methodInfo; }
void _tracer_ItemAddedEvent(TracerItemKeeperSink sink, TracerItem item) { _itemsModified = true; }
private void listView_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e) { e.Item = new ListViewItem(); TracerItem tracerItem = null; // If we are in the last items, make sure to always leave them blank. if (e.ItemIndex <= listView.VirtualListSize - CleanVirtualItemsCount) { if (_itemKeeperSink != null) { tracerItem = _itemKeeperSink.GetFilteredItem(e.ItemIndex); } } if (tracerItem == null) { e.Item.SubItems.Clear(); for (int i = 0; i < listView.Columns.Count; i++) { e.Item.SubItems.Add(string.Empty); } return; } switch (tracerItem.FullType) { case TracerItem.TypeEnum.MethodEntry: e.Item.ImageIndex = 3; break; case TracerItem.TypeEnum.MethodExit: e.Item.ImageIndex = 4; break; case TracerItem.TypeEnum.Trace: e.Item.ImageIndex = 0; break; case TracerItem.TypeEnum.System: e.Item.ImageIndex = 6; break; case TracerItem.TypeEnum.Warning: case (TracerItem.TypeEnum.Warning | TracerItem.TypeEnum.Operation): e.Item.ImageIndex = 5; break; case (TracerItem.TypeEnum.Error | TracerItem.TypeEnum.Operation): case TracerItem.TypeEnum.Error: e.Item.ImageIndex = 2; break; default: // If there are only items with no images, the image column width gets // substraced from the Column.0 width and this causes a bug. e.Item.ImageIndex = 0; break; } if (e.Item.UseItemStyleForSubItems) { e.Item.UseItemStyleForSubItems = false; } Color color = GetPriorityColor(tracerItem.Priority); if (color != e.Item.SubItems[0].BackColor) { e.Item.SubItems[0].BackColor = color; } string day = tracerItem.DateTime.Day.ToString(); if (tracerItem.DateTime.Day == 1) { day += "st"; } else if (tracerItem.DateTime.Day == 2) { day += "nd"; } else if (tracerItem.DateTime.Day == 3) { day += "rd"; } else { day += "th"; } string time = string.Empty; Tracer tracer = _tracer; if (tracer != null) { if (tracer.TimeDisplayFormat == CommonSupport.Tracer.TimeDisplayFormatEnum.ApplicationTicks) {// Application time. time = Math.Round(((decimal)tracerItem.ApplicationTick / (decimal)Stopwatch.Frequency), 6).ToString(); } else if (tracer.TimeDisplayFormat == CommonSupport.Tracer.TimeDisplayFormatEnum.DateTime) {// Date time conventional. time = day + tracerItem.DateTime.ToString(", HH:mm:ss:ffff"); } else {// Combined. time = day + tracerItem.DateTime.ToString(", HH:mm:ss:ffff"); time += " | " + Math.Round(((decimal)tracerItem.ApplicationTick / (decimal)Stopwatch.Frequency), 6).ToString(); } } e.Item.Text = tracerItem.Index + ", " + time; e.Item.SubItems.Add(tracerItem.PrintMessage()); if (string.IsNullOrEmpty(_markingMatch) == false) { if (StringTracerFilter.FilterItem(tracerItem, _markingMatch, null)) { e.Item.BackColor = Color.PowderBlue; } } }
private void listView_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e) { e.Item = new ListViewItem(); TracerItem tracerItem = null; // If we are in the last items, make sure to always leave them blank. if (e.ItemIndex <= listView.VirtualListSize - CleanVirtualItemsCount) { lock (_itemKeeperSink) {// Hold the tracer not allowing it to modify its collection before we read it. if (_itemKeeperSink != null && _itemKeeperSink.FilteredItemsCount > e.ItemIndex) { tracerItem = _itemKeeperSink.FilteredItemsUnsafe[e.ItemIndex]; } } } if (tracerItem == null) { e.Item.SubItems.Clear(); for (int i = 0; i < listView.Columns.Count; i++) { e.Item.SubItems.Add(string.Empty); } return; } switch (tracerItem.FullType) { case TracerItem.TypeEnum.MethodEntry: e.Item.ImageIndex = 3; break; case TracerItem.TypeEnum.MethodExit: e.Item.ImageIndex = 4; break; case TracerItem.TypeEnum.Trace: e.Item.ImageIndex = 0; break; case TracerItem.TypeEnum.System: e.Item.ImageIndex = 6; break; case TracerItem.TypeEnum.Warning: case (TracerItem.TypeEnum.Warning | TracerItem.TypeEnum.Operation): e.Item.ImageIndex = 5; break; case (TracerItem.TypeEnum.Error | TracerItem.TypeEnum.Operation): case TracerItem.TypeEnum.Error: e.Item.ImageIndex = 2; break; } if (e.Item.UseItemStyleForSubItems) { e.Item.UseItemStyleForSubItems = false; } Color color = GetPriorityColor(tracerItem.Priority); if (color != e.Item.SubItems[0].BackColor) { e.Item.SubItems[0].BackColor = color; } string day = tracerItem.DateTime.Day.ToString(); if (tracerItem.DateTime.Day == 1) { day += "st"; } else if (tracerItem.DateTime.Day == 2) { day += "nd"; } else if (tracerItem.DateTime.Day == 3) { day += "rd"; } else { day += "th"; } string time = day + tracerItem.DateTime.ToString(", HH:mm:ss:ffff"); e.Item.Text = tracerItem.Index /*(Tracer.TotalItemsCount - (Tracer.FilteredItemsCount - e.ItemIndex)).ToString()*/ + ", " + time; e.Item.SubItems.Add(tracerItem.PrintMessage()); if (string.IsNullOrEmpty(_markingMatch) == false) { if (StringTracerFilter.FilterItem(tracerItem, _markingMatch, null)) { e.Item.BackColor = Color.MistyRose; } } }
/// <summary> /// /// </summary> public virtual bool ReceiveItem(TracerItem item, bool isFilteredOut) { if (_enabled && (isFilteredOut || _processNonFilteredOutItems)) { bool filteredBySink = false; lock (this) { filteredBySink = !Tracer.FilterItem(_filters, item); } return OnReceiveItem(item, isFilteredOut, filteredBySink); } return true; }
protected override bool OnReceiveItem(TracerItem item, bool isFilteredOutByTracer, bool isFilteredOutBySink) { System.Diagnostics.Trace.WriteLine(item.PrintPrefix(' ') + item.PrintMessage()); return(true); }
/// <summary> /// Received an item, sink it to file. /// </summary> protected override bool OnReceiveItem(TracerItem item, bool isFilteredOutByTracer, bool isFilteredOutBySink) { return(_fileWriter.WriteLine(item.PrintFileLine())); }
/// <summary> /// /// </summary> public override bool FilterItem(TracerItem item) { if (string.IsNullOrEmpty(_positiveFilterString) == false || _negativeFilterStrings != null) { return FilterItem(item, _positiveFilterString, _negativeFilterStrings); } return true; }
/// <summary> /// /// </summary> /// <param name="errorMessage"></param> public static void OperationError(string errorMessage, TracerItem.PriorityEnum priority) { TracerHelper.TraceOperationError(errorMessage); if ((GlobalDiagnosticsMode && priority > TracerItem.PriorityEnum.Medium) || priority == TracerItem.PriorityEnum.Critical) { Debug.Fail(errorMessage); } }
/// <summary> /// Report a simplme message to the report management system. /// </summary> /// <param name="reportMessage"></param> public static void Report(string reportMessage, TracerItem.PriorityEnum priority) { // TODO: Implement tracer item priority properly. if (priority == TracerItem.PriorityEnum.High || priority == TracerItem.PriorityEnum.Critical) { TracerHelper.Trace("***Report*** " + reportMessage); } else { TracerHelper.Trace("Report: " + reportMessage); } }
/// <summary> /// Filter single item, passing it trough all filters. /// </summary> public bool FilterItem(TracerItem item) { return FilterItem(FiltersArray, item); }
/// <summary> /// /// </summary> public override bool FilterItem(TracerItem item) { return(item.Priority >= _minimumPriority); }
public static void Trace(Tracer tracer, string message, TracerItem.PriorityEnum priority) { DoTrace(tracer, TracerItem.TypeEnum.Trace, priority, message); }