예제 #1
0
        /// <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());
            }
        }
예제 #2
0
        ///// <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}>");
            }
        }
예제 #3
0
 public virtual bool ShouldTrace(TraceEventFlag eventType)
 {
     return(this.IsEnabled(eventType));
 }
예제 #4
0
 public bool IsEnabled(TraceEventFlag eventType)
 {
     return((this.types & eventType) == eventType);
 }
예제 #5
0
 public void Enable(TraceEventFlag eventType)
 {
     this.types |= eventType;
 }
예제 #6
0
 public void Disable(TraceEventFlag eventType)
 {
     this.types &= ~eventType;
 }
예제 #7
0
 public void Set(TraceEventFlag eventType)
 {
     this.types = eventType;
 }
예제 #8
0
 public EventTypeFilter(TraceEventFlag eventTypes)
 {
     this.types = eventTypes;
 }