ShouldTrace() публичный Метод

public ShouldTrace ( System eventType ) : bool
eventType System
Результат bool
Пример #1
0
        public void TraceEvent(TraceEventType eventType, int id)
        {
            Initialize();

            if (_internalSwitch.ShouldTrace(eventType) && _listeners != null)
            {
                TraceEventCache manager = new TraceEventCache();

                if (TraceInternal.UseGlobalLock)
                {
                    // we lock on the same object that Trace does because we're writing to the same Listeners.
                    lock (TraceInternal.critSec)
                    {
                        for (int i = 0; i < _listeners.Count; i++)
                        {
                            TraceListener listener = _listeners[i];
                            listener.TraceEvent(manager, Name, eventType, id);
                            if (Trace.AutoFlush)
                            {
                                listener.Flush();
                            }
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < _listeners.Count; i++)
                    {
                        TraceListener listener = _listeners[i];
                        if (!listener.IsThreadSafe)
                        {
                            lock (listener)
                            {
                                listener.TraceEvent(manager, Name, eventType, id);
                                if (Trace.AutoFlush)
                                {
                                    listener.Flush();
                                }
                            }
                        }
                        else
                        {
                            listener.TraceEvent(manager, Name, eventType, id);
                            if (Trace.AutoFlush)
                            {
                                listener.Flush();
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
		public void ShouldTrace ()
		{
			SourceSwitch s = new SourceSwitch ("foo");
			s.Level = SourceLevels.Verbose;
			Assert.IsTrue (s.ShouldTrace (TraceEventType.Critical), "#1");
			Assert.IsTrue (s.ShouldTrace (TraceEventType.Error), "#2");
			Assert.IsTrue (s.ShouldTrace (TraceEventType.Warning), "#3");
			Assert.IsTrue (s.ShouldTrace (TraceEventType.Information), "#4");
			Assert.IsTrue (s.ShouldTrace (TraceEventType.Verbose), "#5");
			Assert.IsFalse (s.ShouldTrace (TraceEventType.Start), "#6");
			Assert.IsFalse (s.ShouldTrace (TraceEventType.Stop), "#7");
			Assert.IsFalse (s.ShouldTrace (TraceEventType.Suspend), "#8");
			Assert.IsFalse (s.ShouldTrace (TraceEventType.Resume), "#9");
			Assert.IsFalse (s.ShouldTrace (TraceEventType.Transfer), "#10");
		}
Пример #3
0
 public void TraceData(TraceEventType eventType, int id, object data)
 {
     if (source_switch.ShouldTrace(eventType))
     {
         lock (((ICollection)listeners).SyncRoot)
         {
             foreach (TraceListener listener in listeners)
             {
                 listener.TraceData(null, Name, eventType, id, data);
             }
         }
     }
 }
Пример #4
0
 public void TraceData(
     TraceEventType eventType, int id, object data)
 {
     if (!source_switch.ShouldTrace(eventType))
     {
         return;
     }
     lock (((ICollection)listeners).SyncRoot) {
         foreach (TraceListener tl in listeners)
         {
             tl.TraceData(new TraceEventCache(), Name, eventType, id, data);
         }
     }
 }