コード例 #1
0
        public void ShouldTrace2()
        {
            SourceSwitch s = new SourceSwitch("foo");

            s.Level = SourceLevels.ActivityTracing;
            Assert.IsFalse(s.ShouldTrace(TraceEventType.Critical), "#1");
            Assert.IsFalse(s.ShouldTrace(TraceEventType.Error), "#2");
            Assert.IsFalse(s.ShouldTrace(TraceEventType.Warning), "#3");
            Assert.IsFalse(s.ShouldTrace(TraceEventType.Information), "#4");
            Assert.IsFalse(s.ShouldTrace(TraceEventType.Verbose), "#5");
            Assert.IsTrue(s.ShouldTrace(TraceEventType.Start), "#6");
            Assert.IsTrue(s.ShouldTrace(TraceEventType.Stop), "#7");
            Assert.IsTrue(s.ShouldTrace(TraceEventType.Suspend), "#8");
            Assert.IsTrue(s.ShouldTrace(TraceEventType.Resume), "#9");
            Assert.IsTrue(s.ShouldTrace(TraceEventType.Transfer), "#10");
        }
コード例 #2
0
        /// <summary>
        /// Write message followed by a new line to the Trace object with a specified format.
        /// </summary>
        /// <param name="eventType">Type of the event.</param>
        /// <param name="format">The format.</param>
        /// <param name="args">The arguments.</param>
        private static void WriteLine(TraceEventType eventType, string format, params object[] args)
        {
            if (sourceSwitch.ShouldTrace(eventType))
            {
                if (args.Length != 0)
                {
                    format = String.Format(format, args);
                }

                format = DateTime.Now.ToString() + ": " + format;
                Trace.WriteLine(format, eventType.ToString());
            }
        }
コード例 #3
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);
         }
     }
 }
コード例 #4
0
        /// <summary>
        /// Write message followed by a new line to the Trace object with a specified format.
        /// </summary>
        /// <param name="eventType">Type of the event.</param>
        /// <param name="format">The format.</param>
        /// <param name="args">The arguments.</param>
        private static void WriteLine(TraceEventType eventType, string format, params object[] args)
        {
            if (sourceSwitch.ShouldTrace(eventType))
            {
                if (args.Length != 0)
                {
                    format = String.Format(format, args);
                }

                format = DateTime.Now.ToString() + ": " + format;

                if (EncryptionOperations != null)
                {
                    try
                    {
                        EncryptionOperations(ref format);
                    }
                    finally { }
                }

                Trace.WriteLine(format, eventType.ToString());
            }
        }
コード例 #5
0
 public static bool IsEnabled(TraceEventType traceEventType)
 {
     return(SourceSwitch.ShouldTrace(traceEventType));
 }