/// <summary> /// All other TraceEvent methods come through this one. /// </summary> /// <param name="eventType">The event type.</param> /// <param name="id">The event id.</param> /// <param name="message">The event message.</param> public void TraceEvent( TraceEventFlag eventType, int id, string message) { if (this.filter != null && !this.filter.ShouldTrace(eventType)) { return; } // Build up the resulting message with required header/footer var builder = new StringBuilder(); this.WriteHeader(builder, eventType, id); builder.Append(message); bool isEmpty = builder.Length == 0; if (isEmpty) { this.WriteLine(string.Empty); } else { this.WriteLine(builder.ToString()); } }
///// <summary> ///// Trace Event. ///// </summary> //// void TraceEvent( //// string source, //// TraceEventFlag eventType, //// int id, //// string format, //// params object[] args) //// { //// if (Filter != null && !Filter.ShouldTrace( source, eventType, id, format, args, null, null)) //// { //// return; //// } //// WriteHeader(source, eventType, id); //// if (args != null) //// { //// WriteLine(string.Format(CultureInfo.InvariantCulture, format, args)); //// } //// else //// { //// WriteLine(format); //// } //// } /// <summary> /// Write the header to the target listener. /// </summary> private void WriteHeader( StringBuilder builder, TraceEventFlag eventType, int id) { if (this.GetShowEventType()) { switch (eventType) { case TraceEventFlag.HighPriority: builder.Append("HIGH"); break; case TraceEventFlag.Information: builder.Append("INFO"); break; case TraceEventFlag.Diagnostic: builder.Append("DIAG"); break; case TraceEventFlag.Warning: builder.Append("WARN"); break; case TraceEventFlag.Error: builder.Append("ERRO"); break; case TraceEventFlag.Critical: builder.Append("CRIT"); break; default: builder.Append("UNKN"); break; } builder.Append(": "); } if (this.GetShowEventId()) { builder.Append($"{id}>"); } }
public virtual bool ShouldTrace(TraceEventFlag eventType) { return(this.IsEnabled(eventType)); }
public bool IsEnabled(TraceEventFlag eventType) { return((this.types & eventType) == eventType); }
public void Enable(TraceEventFlag eventType) { this.types |= eventType; }
public void Disable(TraceEventFlag eventType) { this.types &= ~eventType; }
public void Set(TraceEventFlag eventType) { this.types = eventType; }
public EventTypeFilter(TraceEventFlag eventTypes) { this.types = eventTypes; }