TraceEvent() public method

public TraceEvent ( System eventCache, string source, System eventType, int id ) : void
eventCache System
source string
eventType System
id int
return void
        public void TraceEvent(TraceEventType eventType, int id, string format, params object[] args)
        {
            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, format, args);
                            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, format, args);
                                if (Trace.AutoFlush)
                                {
                                    listener.Flush();
                                }
                            }
                        }
                        else
                        {
                            listener.TraceEvent(manager, Name, eventType, id, format, args);
                            if (Trace.AutoFlush)
                            {
                                listener.Flush();
                            }
                        }
                    }
                }
            }
        }
        public void TraceEvent(TraceEventType eventType, int id, string message)
        {
            // Ensure that config is loaded
            Initialize();

            TraceEventCache manager = new TraceEventCache();

            if (internalSwitch.ShouldTrace(eventType) && listeners != null)
            {
                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, message);
                            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, message);
                                if (Trace.AutoFlush)
                                {
                                    listener.Flush();
                                }
                            }
                        }
                        else
                        {
                            listener.TraceEvent(manager, Name, eventType, id, message);
                            if (Trace.AutoFlush)
                            {
                                listener.Flush();
                            }
                        }
                    }
                }
            }
        }
        public void TraceEvent(TraceEventType eventType, int id, string format, params object[] args)
        {
            this.Initialize();
            TraceEventCache eventCache = new TraceEventCache();

            if (this.internalSwitch.ShouldTrace(eventType) && (this.listeners != null))
            {
                if (TraceInternal.UseGlobalLock)
                {
                    lock (TraceInternal.critSec)
                    {
                        for (int j = 0; j < this.listeners.Count; j++)
                        {
                            TraceListener listener = this.listeners[j];
                            listener.TraceEvent(eventCache, this.Name, eventType, id, format, args);
                            if (Trace.AutoFlush)
                            {
                                listener.Flush();
                            }
                        }
                        return;
                    }
                }
                for (int i = 0; i < this.listeners.Count; i++)
                {
                    TraceListener listener2 = this.listeners[i];
                    if (!listener2.IsThreadSafe)
                    {
                        lock (listener2)
                        {
                            listener2.TraceEvent(eventCache, this.Name, eventType, id, format, args);
                            if (Trace.AutoFlush)
                            {
                                listener2.Flush();
                            }
                            continue;
                        }
                    }
                    listener2.TraceEvent(eventCache, this.Name, eventType, id, format, args);
                    if (Trace.AutoFlush)
                    {
                        listener2.Flush();
                    }
                }
            }
        }
Beispiel #4
0
 public void TraceEventButNotToUI(LogLevels eventType, int id, string message, TraceEventCache tec = null)
 {
     if (!ShouldTrace(eventType))
     {
         return;
     }
     if (tec == null)
     {
         tec = new TraceEventCache();
     }
     System.Diagnostics.TraceListener tl = ts.Listeners["FileLog"];
     if (tl != null)
     {
         tl.TraceEvent(tec, ts.Name, (TraceEventType)eventType, id, message);
     }
     tl = ts.Listeners["console"];
     if (tl != null)
     {
         tl.TraceEvent(tec, ts.Name, (TraceEventType)eventType, id, message);
     }
 }
Beispiel #5
0
 public void TraceEventFileOnly(LogLevels eventType, int id, string message, TraceEventCache tec)
 {
     if (!ShouldTrace(eventType))
     {
         return;
     }
     System.Diagnostics.TraceListener tl = ts.Listeners["FileLog"];
     if (tl != null)
     {
         tl.TraceEvent(tec, ts.Name, (TraceEventType)eventType, id, message);
     }
 }
Beispiel #6
0
            public void TraceExceptionButNotToUI(Exception ex, bool stack = false)
            {
                TraceEventCache tec = new TraceEventCache();

                System.Diagnostics.TraceListener tl = ts.Listeners["FileLog"];
                if (tl != null)
                {
                    tl.TraceEvent(tec, ts.Name, TraceEventType.Error, 999, ex.Source + ":" + ex.Message);
                    if (stack)
                    {
                        tl.TraceEvent(tec, ts.Name, TraceEventType.Error, 998, FlattenChars(ex.StackTrace, '*', 0x269b)); // unicode atom symbol
                    }
                }
                tl = ts.Listeners["console"];
                if (tl != null)
                {
                    tl.TraceEvent(tec, ts.Name, TraceEventType.Error, 999, ex.Source + ":" + ex.Message);
                    if (stack)
                    {
                        tl.TraceEvent(tec, ts.Name, TraceEventType.Error, 998, FlattenChars(ex.StackTrace, '*', 0x269b)); // unicode atom symbol
                    }
                }
            }
Beispiel #7
0
        public void TraceEvent(TraceEventType eventType, int id, string format, params object[] args)
        {
            if (!this.source_switch.ShouldTrace(eventType))
            {
                return;
            }
            object syncRoot = ((ICollection)this.listeners).SyncRoot;

            lock (syncRoot)
            {
                foreach (object obj in this.listeners)
                {
                    TraceListener traceListener = (TraceListener)obj;
                    traceListener.TraceEvent(null, this.Name, eventType, id, format, args);
                }
            }
        }